[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pal-Kristian Engstad <engstad@n...> |
| Subject: | Re: [Caml-list] Why is (@) written in O'Caml? |
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