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 HAA09128; Fri, 9 Apr 2004 07:40:47 +0200 (MET DST) 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 HAA08175 for ; Fri, 9 Apr 2004 07:40:45 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i395egYM010083 for ; Fri, 9 Apr 2004 07:40:44 +0200 Received: from [192.168.1.200] (ppp116-94.lns1.syd2.internode.on.net [150.101.116.94]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i395eUvM007328; Fri, 9 Apr 2004 15:10:34 +0930 (CST) Subject: Re: [Caml-list] Dynamically evaluating OCaml code From: skaller Reply-To: skaller@users.sourceforge.net To: Richard Jones Cc: Ocaml Mailing List In-Reply-To: <20040408151427.GA740@redhat.com> References: <20020104004356.GA1672@mev> <20040408133727.GC29195@excelhustler.com> <20040408145606.GA18473@fichte.ai.univie.ac.at> <20040408151427.GA740@redhat.com> Content-Type: text/plain Message-Id: <1081489229.20677.63.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 09 Apr 2004 15:40:29 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 dynamically:01 sourceforge:01 2004:99 2004:99 val:01 9660:01 glebe:01 tokens:01 inefficient:01 ocaml:01 ocaml:01 mutable:01 int:01 token:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 193 On Fri, 2004-04-09 at 01:14, Richard Jones wrote: > On Thu, Apr 08, 2004 at 04:56:06PM +0200, Markus Mottl wrote: > > Yes, it's hard to do this with the current standard library. The question > > is: who needs these functions anyway? I can't remember ever having felt > > a need for them. > > My "private library" defines: > > val first : int -> 'a list -> 'a list And I need 'last' often (get last element). > which returns the first n members of a list. As for slicing the > middle from a list, I tend to think that the original poster should > probably be using a different, more suitable structure. Perhaps an > Array if he wants random access. Sometimes inefficient operations are necessary, there's no universally good data structure. I need 'last' element of a list, because sometimes my lists happen to be in the wrong order. I won't use an Ocaml array, even if it were universally more efficient for what I want, because it's mutable! Fact is, most of my lists are so short I don't care two hoots about efficiency. I care only for the couple of really BIG lists I keep (eg: list of all tokens of a program). Even then I'd rather get it right and keep it simple, and perhaps worry about performance down the track. More than one solution may exist. For example, I now cache the result of tokenisation, parsing, and macro processing on disk with Marshal, which saves one heck of a lot more time than merely changing the data structure I use to represent program text at the token level -- there's nothing faster than building *no* data structure :D Actually, the lists are so much easier to work with, because there is builtin support for forward iteration: let filt a b = match a with | [] -> b | COMMENT s :: t -> filt t b | h :: t -> filt t (h::b) Try doing that with an array .. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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