From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA13027; Thu, 5 Dec 2002 22:53:40 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA13121 for ; Thu, 5 Dec 2002 22:53:39 +0100 (MET) Received: from slave-dog.naughtydog.com (naughtydog200.brandx.net [209.55.75.200]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id gB5LrbX08335 for ; Thu, 5 Dec 2002 22:53:38 +0100 (MET) Received: from SMTP agent by mail gateway Thu, 05 Dec 2002 13:55:48 -0800 Received: from katn-dog (engstad@katn-dog.naughtydog.com [10.0.0.90]) by slave-dog.naughtydog.com (SGI-8.9.3/8.9.3) with ESMTP id NAA40182; Thu, 5 Dec 2002 13:55:43 -0800 (PST) Content-Type: text/plain; charset="iso-8859-1" From: Pal-Kristian Engstad Organization: Naughty Dog, Inc. To: Oleg , Pal-Kristian Engstad , caml-list@inria.fr Subject: Re: [Caml-list] Why is (@) written in O'Caml? Date: Thu, 5 Dec 2002 13:55:41 -0800 User-Agent: KMail/1.4.3 References: <200212051547.09337.oleg_inconnu@myrealbox.com> <200212051316.08952.engstad@naughtydog.com> <200212051624.37333.oleg_inconnu@myrealbox.com> In-Reply-To: <200212051624.37333.oleg_inconnu@myrealbox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200212051355.41175.engstad@naughtydog.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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