[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic questions about elisp

From: tomas
Subject: Re: Basic questions about elisp
Date: Sun, 8 Nov 2009 10:46:18 +0100
User-agent: Mutt/1.5.15+20070412 (2007-04-11)

Hash: SHA1

On Sat, Nov 07, 2009 at 06:49:52AM -0800, Francis Moreau wrote:
> On 6 nov, 22:18, address@hidden (Pascal J. Bourguignon) wrote:
> > Francis Moreau <address@hidden> writes:


> > > Actually the same stands for the implementation of the list, where
> > > nconc, length... are O(n). I wouldn't have thought that lists are really
> > > implemented by the car & cdr thing only.
> >
> > Why not?  If people have been repeating for 50 years that lisp lists
> > are implemented with cons, car and cdr...
> Because I can understand there were some memory constraints 50 years
> ago that force lisp lists to be as small as possible. But I would have
> thought lisp lists (or (e)lisp) to evolve as computer memories did.

There's no "one data structure fits all" philosophy here. Use list for
"list things" and arrays for "array things". Nowadays all Lisps have
some form or other of array.

And still, lists are among the strongest points of Lisp. They are
simple and flexible, they are the representation of Lisp programs. They
are the reason why Lisp programmers are writing programs that write
programs ever since ~50 years ago.

If a list doesn't fit your bill, by all means: use defstruct, use
arrays, use hashes. But (as Pascal pointed out), sometimes lists fit a
bill quite unexpectedly, if you are willing to think flexibly (e.g. push
new elements at the head instead of append, etc).

Ah, btw. Some Lisp implementations optimize runs of lists as arrays
behind the scenes (search for "cdr compression"). But you still get this
nice, simple and expressive programming interface.

- -- tomás
Version: GnuPG v1.4.6 (GNU/Linux)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]