[ENH] Lispy list functions
Peter Smet
peter.smet at flinders.edu.au
Thu Sep 9 00:54:58 UTC 1999
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)
For this to work you must guarantee that tail
always returns a list. Otherwise you end up sending the
message 'head' to a single element (which it won't
understand). My knowledge of Scheme and Lisp is probably
off here, but with Haskell and Prolog the tail is always
a collection and not an element. ie:
#(a b c) tail "should return #(a b)
#(a b) tail "should return #(b), and not b
#(b) tail "should return #()
Any functional programmers out there that can shed some
light on this?
>>One comment. In prolog, scheme, lisp etc, the head
>>always returns a single element, and the tail always returns
>>a list (and nil is an empty list).
>
>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.
>
>Mayer
>
More information about the Squeak-dev
mailing list
|