(define answer-for-12.1 (lambda () (list ;; 1.exp: 1 ;; env: {} ;; cnt: [primother +, 2, {}, [done]] ;; Adds 2 to 1, then done. 3 ;; 2.exp: x ;; env: {x=12, {x=10, {}}} ;; cnt: [primother +, x, {x=10, {}}, [done]] ;; Evals x to 12, ;; then x to 10 ;; then adds 12 + 10 22 ;; 3.val: 10 ;; cnt: [app , [apparg 12, {}, [done]]] ;; Applies the closure to 10: ;; binding x to 10, evaluate proc(y)+(y, 5) to get ;; ;; then applies the resulting closure to the evaluation of 12, 17 ;; 4.val: ;; cnt: [apparg 10, {x=6, {}}, [apparg 12, {x=6, {}}, [done]]] ;; Keeps the closure and ;; evaluate the argument expression, 10, then applies the closure ;; to 10; gives bdy proc(y)-(y, x) in the environment {x=10, {x = 6, {}}}. ;; The result is a closure: . ;; Evaluate the closure's argument, 12, then apply it: ;; -(y, x) in the environment {y=12, {x=10, {x = 6, {}}}} 12))) (define answer-for-12.2 (lambda () ;; Register 1: 0 ;; Register 2: 3 ;; To space: 1 17 12 4 0 2 3 3 3 3 5 3 1 14 0 ;; Address: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ;; Records: ^ ^ ^ ^ ^ ;; ;; New reg 1: 0 ;; New reg 2: 3 ;; New to space: 1 17 5 4 0 1 14 0 0 0 0 0 0 0 0 ;; Address: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ;; Records: ^ ^ ^ ;; Was at: 0 3 12 ;; Why copied: Reg1 reg2 rec@3 (list 0 3 1 17 5 4 0 1 14 0 0 0 0 0 0 0 0))) (define answer-for-12.3 (lambda () (list ;; 1.zero #t ;; 2.(add1 zero) #t ;; 3.(sub1 (add1 zero)) #f ;; because grammar doesn't allow sub1 ;; 4.(add1 (sub1 zero)) #f ;; because grammar doesn't allow sub1 ;; 5.(add1 (add1 (add1 zero))) #t ;; because zero is a V ;; so (add1 zero) is a V ;; so (add1 (add1 zero)) is a V ;; so (add1 (add1 (add1 zero))) is a V ))) (define answer-for-12.4 (lambda () (list ;; 1.zero #t ;; in 0 steps ;; 2.(add1 (sub1 zero)) #f ;; no rule matching this shape ;; 3.(sub1 (add1 zero)) #t ;; (sub1 (add1 zero)) -> zero ;; 4.(sub1 (add1 zero)) - same as #3 #t ;; 5.(sub1 (sub1 (add1 (add1 zero)))) #t ;; (sub1 (sub1 (add1 (add1 zero)))) ;; -> (sub1 (add1 zero)) by E = (sub1 []) ;; and M = (sub1 (add1 V)) ;; where V = (add1 zero) ;; -> zero ;; 6.(sub1 (add1 (sub1 (add1 zero)))) #t ;; (sub1 (add1 (sub1 (add1 zero)))) ;; -> (sub1 (add1 zero)) by E = (sub1 (add1 [])) ;; and M = (sub1 (add1 zero)) ;; -> zero ;; 7.(sub1 (add1 (sub1 (sub1 (add1 zero))))) #f ;; (sub1 (add1 (sub1 (sub1 (add1 zero))))) ;; -> (sub1 (add1 (sub1 zero))) by E = (sub1 (add1 (sub1 []))) ;; and M = (sub1 (add1 zero)) ;; stuck, since (sub1 zero) can't be reduced, and it isn't a value )))