CS 136 Tutorials - Spring 2007

CS 136 Home » Tutorials » Tutorial 2: Service Managers and Destructive Methods »

Solution for second semantics example

The part of the code marked in green is the part which is about to be expanded, and the part marked in red is the part which was just expanded.

  First Next
(define lst-1 (cons 'b (cons 'c empty)))
(define lst-2 (cons 'a (rest lst-1)))
(set-rest! (rest lst-2) (cons 'd empty))
(set! lst-1 (cons 'a (cons 'd empty)))
(set-rest! lst-2 (rest (rest lst-2)))
(set-rest! lst-1 empty)