Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Why is (@) written in O'Caml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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 01:24 pm, Oleg wrote:
> On Thursday 05 December 2002 04:16 pm, Pal-Kristian Engstad wrote:
> > But, that is _exactly_ what the function above does!
>
> It's not about *what* it does, but *how* (@) does it. (@) is recursive and
> not tail-recursive.

Okey - I see where you're coming from. Since we know that we're creating a new 
copy of a list, we know there will be references to it elsewhere, hence we 
may see it as a mutable list and do something like:

struct cell { value *hd; cell* tl; };
newlist = nil;
prev = nil;
list = l1;
/* copy l1 */
while (list != nil) {
   pnew = alloc(list);           /* Allocate new cell. */
   if (!newlist) newlist = pnew; /* Mark first cell. */
   pnew->hd = list->hd;          /* Copy data at cell. */
   pnew->tl = nil;               /* Init to nil. */
   if (prev) prev->tl = pnew;    /* Link previous cell to this. */
   prev = pnew;                  /* Update previous. */
   list = list->tl;              /* Get next l1 cell. */
}
if (prev) {
   prev->tl = l2;
   return newlist;
}
else {
   return l2;
}

Is that what you mean?

PKE.

-------------------
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