SICP exercise 2.17

From Drewiki

Jump to: navigation, search

Problem

Define a procedure last-pair that returns the list that contains only the last element of a given (nonempty) list:

 

Output:

(34)


Solution

We need a procedure that cdrs down the list:

 

Note that it's safe to cdr the list before checking that the cdr is empty, because the constraint on the input list is that it's non-empty.

Test:

 

Output:

(34)
Personal tools