Blob


1 (define (mystery x)
2 (define (loop x y)
3 (if (null? x)
4 y
5 (let ((temp (cdr x)))
6 (set-cdr! x y)
7 (loop temp x))))
8 (loop x '()))
10 Loop uses the ``temporary'' variable temp to hold the old value of the cdr of x, since the set-cdr! on the next line destroys the cdr. Explain what mystery does in general. Suppose v is defined by (define v (list 'a 'b 'c 'd)). Draw the box-and-pointer diagram that represents the list to which v is bound. Suppose that we now evaluate (define w (mystery v)). Draw box-and-pointer diagrams that show the structures v and w after evaluating this expression. What would be printed as the values of v and w ?