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 WAA12212; Thu, 5 Dec 2002 22:14:06 +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 WAA11491 for ; Thu, 5 Dec 2002 22:14:05 +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 gB5LE4X07230 for ; Thu, 5 Dec 2002 22:14:04 +0100 (MET) Received: from SMTP agent by mail gateway Thu, 05 Dec 2002 13:16:14 -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 NAA52284; Thu, 5 Dec 2002 13:16:09 -0800 (PST) Content-Type: text/plain; charset="iso-8859-1" From: Pal-Kristian Engstad Organization: Naughty Dog, Inc. To: Oleg , caml-list@inria.fr Subject: Re: [Caml-list] Why is (@) written in O'Caml? Date: Thu, 5 Dec 2002 13:16:08 -0800 User-Agent: KMail/1.4.3 References: <200212051547.09337.oleg_inconnu@myrealbox.com> In-Reply-To: <200212051547.09337.oleg_inconnu@myrealbox.com> MIME-Version: 1.0 Message-Id: <200212051316.08952.engstad@naughtydog.com> Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by slave-dog.naughtydog.com id NAA52284 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday 05 December 2002 12:47 pm, Oleg wrote: > let rec (@) l1 l2 =3D > match l1 with > [] -> l2 > > | hd :: tl -> hd :: (tl @ l2) > > The O'Caml implementation of (@) is recursive and not tail-recursive. A= ll > one really has to do during "append" is copy l1 and set the last elemen= t's > CDR to l2. I can see why this can not be done in O'Caml itself, but sin= ce > (@) 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,=20 that is _exactly_ what the function above does!=20 let copy l1 =3D=20 match l1 with [] -> [] | hd :: tl -> hd :: copy tl Right? So, the only change is the extra argument l2, that is being append= ed=20 onto the list when l1 is empty.=20 PKE. --=20 _ =20 \`. P=E5l-Kristian Engstad, Senior Software Engineer, \ `| Naughty Dog, Inc., 1315 3rd Street Promenade,=20 __\ |`. Santa Monica, CA 90046, USA. (310) 752-1000 x799.=20 / /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