Linked lists (was Re: Typing system vs. Java
Alex Martelli
aleax at aleax.it
Wed Aug 8 05:04:10 EDT 2001
<xtian at hyperactive.co.nz> wrote in message
news:3b707aa4.591122937 at news.supernews.com...
...
> def cons(car, cdr):
> return car, cdr
>
> x = cons(1, ())
> x -> (1, ())
> x = cons(2, x)
> x -> (2, (1, ()))
>
> (You'd have to do the proper cons(1, ()) to start it off - otherwise I
> guess it'd be a dotted pair.)
Uh, yes, cons does build a dotted-pair (and car and cdr access the
two halves of the pair) -- that's what they do in every LISP I know
(and () does look like a good representation for NIL) -- lists are
dotted-pairs of their head and their tail (with NIL being the cdr
at the end of the list). Sorry for not pointing this out earlier!
> That's pretty spectacularly neat.
>
> Nice one, Alex.
Why, thanks -- it didn't look like anything special, and was meant
as more of a deadpan-humor quip (as in, "of COURSE you can build
LISP-ish linked lists, since you can build pairs and take them
apart again")...
Alex
More information about the Python-list
mailing list