caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pal-Kristian Engstad <engstad@naughtydog.com>
To: Oleg <oleg_inconnu@myrealbox.com>, caml-list@inria.fr
Subject: Re: [Caml-list] Why is (@) written in O'Caml?
Date: Thu, 5 Dec 2002 13:16:08 -0800	[thread overview]
Message-ID: <200212051316.08952.engstad@naughtydog.com> (raw)
In-Reply-To: <200212051547.09337.oleg_inconnu@myrealbox.com>

On Thursday 05 December 2002 12:47 pm, Oleg wrote:
> let rec (@) l1 l2 =
>   match l1 with
>     [] -> l2
>
>   | hd :: tl -> hd :: (tl @ l2)
>
> The O'Caml implementation of (@) is recursive and not tail-recursive. All
> one really has to do during "append" is copy l1 and set the last element's
> CDR to l2. I can see why this can not be done in O'Caml itself, but since
> (@) is such a common operation, I'm wondering why it was decided to
> implement it inefficently in O'Caml itself?

You say you want to copy l1 and then set the last element of tail to l2? But, 
that is _exactly_ what the function above does! 

let copy l1 = 
  match l1 with
    [] -> []
  | hd :: tl -> hd :: copy tl

Right? So, the only change is the extra argument l2, that is being appended 
onto the list when l1 is empty. 

PKE.
-- 
  _       
  \`.       Pål-Kristian Engstad, Senior Software Engineer,
   \ `|     Naughty Dog, Inc., 1315 3rd Street Promenade, 
  __\ |`.   Santa Monica, CA 90046, USA. (310) 752-1000 x799. 
    /  /o   mailto:engstad@naughtydog.com http://www.naughtydog.com
   /  '~    mailto:mrengstad@yahoo.com    http://www.engstad.com
  / ,'      Hang-gliding Rulez!
  ~'

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-12-05 21:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-05 20:47 Oleg
2002-12-05 21:16 ` Pal-Kristian Engstad [this message]
2002-12-05 21:24   ` Oleg
2002-12-05 21:55     ` Pal-Kristian Engstad
2002-12-05 23:27       ` Oleg
2002-12-05 23:53         ` Pal-Kristian Engstad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200212051316.08952.engstad@naughtydog.com \
    --to=engstad@naughtydog.com \
    --cc=caml-list@inria.fr \
    --cc=oleg_inconnu@myrealbox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).