[ENH] Lispy list functions
Eugene Wallingford
wallingf at nova.cs.uni.edu
Thu Sep 9 02:05:35 UTC 1999
>>This is simply not true. (cons A B) returns the ordered pair (A . B) where
>>A, B are some Scheme or LISP objects. car and cdr are the first and second
>>projections, respectively. Thus:
>>
>>(car (cons 'a 'b)) => a
>>(cdr (cons 'a 'b)) => b
>>
>>And this is standardized in both Common LISP, Scheme, and if I'm not
>>mistaken, Prolog as well.
>
> If this is the case, and tail does on occassion return a single element,
> then statements like taking the head of a list's tail just don't work.
>
> (list tail) head (Smalltalk syntax)
The cdr of a cons can indeed point to something other than a list.
But when the cdr of the last cons in a "list" ends with an atom,
it is not a "proper list". I prefer not to think of it as a list
at all, for the reason Peter mentions. So-called dotted pairs,
where the car and cdr of a cons cell both point to atoms, are
sometimes used as pairs, say, to create a simple association.
But when working with lists, one almost always maintains the
convention that the cdr of the last cell is nil, the empty list.
When I have implemented LispyList classes in other languages
(Smalltalk and Java), I have always dispensed with Lisp's dotted
lists and followed the "end in the empty list" convention.
---- Eugene
More information about the Squeak-dev
mailing list
|