Re: cdr vs. nthcdr



"lojic" <lojicdotcom@xxxxxxxxx> writes:

I'm sure I have a fundamental misunderstanding wrt cdr & nthcdr, but
the fact that the following expression is nil bothers me:

(and
lst
(eql
(eql
(car lst)
(nth 0 lst))
(eql
(cdr lst)
(nthcdr 0 lst))))

Why do you assume that the car and cdr of a cons should be eql?

I discovered this while working through "ANSI Common Lisp" and seeing
the following on p. 40:

(maplist #'(lambda (x) x) '(a b c))

which gives

((A B C) (B C) (C))

where I expected

((B C) (C))

since (cdr '(a b c)) gives (B C)

CLHS says:

,----
| function is first applied to the lists themselves, and then to the
| cdr of each list, and then to the cdr of the cdr of each list, and
| so on.
`----

--
Stefan.
.