Blame


1 665c255d 2023-08-04 jrmu (define (mystery x)
2 665c255d 2023-08-04 jrmu (define (loop x y)
3 665c255d 2023-08-04 jrmu (if (null? x)
4 665c255d 2023-08-04 jrmu y
5 665c255d 2023-08-04 jrmu (let ((temp (cdr x)))
6 665c255d 2023-08-04 jrmu (set-cdr! x y)
7 665c255d 2023-08-04 jrmu (loop temp x))))
8 665c255d 2023-08-04 jrmu (loop x '()))
9 665c255d 2023-08-04 jrmu
10 665c255d 2023-08-04 jrmu 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 ?