Next: Constructors and Selectors
Up: Compound Data: Lists of
Previous: Compound Data: Lists of
When you type
(cons 1 empty)
in the interaction window, DrScheme replies with
(cons 1 empty)
DrScheme's reply is the same as your input expression because there is
no shorter name for the list containing the number 1.
On the other hand, enter
(cons (+ 1 2) empty)
and DrScheme replies with
(cons 3 empty)
In this case, (+ 1 2) can be reduced to the simpler
3. But, as before, there is no simpler name for a list
containing 3 other than (cons 3 empty).
The first and rest Operators
The first and rest operators only operate on
lists created with cons, i.e., non-empty lists. So
(first empty)
gives the error message:
first: expects type <non-empty list> as 1st arg: given empty
Exercise Notes
Exercise 5.1.5 The
function in Scheme is
sqrt.
PLT