[Home] [Syllabus] [Assignments] [Resources]This page contains problem set assignments for the course. The assignments will be added as they become available.
swaptakes a single argument. If it is an atom (i.e. not a pair), it just returns the argument. If it's a pair, it switches the car and the cdr. For instance:
(swap (cons 5 8)) >(8 . 5) (swap '(2 3 4)) >((3 4) . 2) ; Why? (swap 5) > 5
deep-swapis a recursive version of swap: it recursively swaps all cons-cells in the arguments. Test this function carefully. What happens if it's applied to a list? Guess what happens when it's applied as follows:
Now try it. Is that what you expected? Can you explain the results?
(define x (cons 3 4)) (define y (cons x x)) (deep-swap y)
What is z? Test it. How can we get the result of the expression, given z?
(define z (cons + '(2 3)))
The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.