Exercise 1.4.13
FIRST, REST, and LAST
In addition to car
and cdr
, it's also possible to manipulate Cons-Cells using the first
and rest
functions. They're just different names for the same functions. first
is the same as car
* (cons 'a 'b)
(A . B)
* (car (cons 'a 'b))
A
* (first (cons 'a 'b))
A
and rest
is the same as cdr
* (cons 1 2)
(1 . 2)
* (cdr (cons 1 2))
2
* (rest (cons 1 2))
2
A third function, last
, lets you get at the last Cons-Cell in a particular series.
* (last (cons 1 (cons 2 (cons 3 nil))))
(3)
* (last (cons 1 2))
(1 . 2)
* (last (list 3 4 5))
(5)