Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Dynamically evaluating OCaml code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Dynamically evaluating OCaml code
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