rushing:~/python/eopl/9.4$ python interp.py --> - define test = proc (x) ... while greater(x,0) do ... begin ... print (x); ... x := sub1(x) ... end ... expanded to: ['definition', 'test', ['proc', ['x'], ['app', ['proc', ['_g0'], ['app', ['proc', ['ignore', 'thunk'], ['app', ['varref', 'thunk'], []]], [['app', ['proc', ['_g1'], ['varassign', '_g0', ['varref', '_g1']]], [['proc', [], ['conditional', ['app', ['varref', 'greater'], [['varref', 'x'], ['lit', 0]]], ['app', ['proc', ['ignore', 'thunk'], ['app', ['varref', 'thunk'], []]], [['app', ['proc', ['ignore', 'thunk'], ['app', ['varref', 'thunk'], []]], [['app', ['varref', 'print'], [['varref', 'x']]], ['proc', [], ['varassign', 'x', ['app', ['varref', 'sub1'], [['varref', 'x']]]]]]], ['proc', [], ['app', ['varref', '_g0'], []]]]], ['lit', 0]]]]], ['proc', [], ['app', ['varref', '_g0'], []]]]]], [['lit', 0]]]]] => [0 environments] --> test(10) expanded to: ['app', ['varref', 'test'], [['lit', 10]]] => [10] [9] [8] [7] [6] [5] [4] [3] [2] [1] 0 [56 environments] --> --> define resume = 0 => [0 environments] --> - define makecoroutine = proc (body) let lcs = 0 in letrecproc newcoroutine (value) = lcs(value); localresume (cont, value) = let receivedvalue = letcont localcont in begin lcs := localcont; cont (value) end in begin resume := localresume; receivedvalue end in letcont exit in begin body(localresume (exit, newcoroutine)); error() end => [0 environments] --> - define example = proc () letcont returncont in let co1 = 0; co2 = 0 in begin co1 := makecoroutine ( proc (initval1) begin print(1); print(initval1); initval1 := resume (co2, add1 (initval1)); print (1); print (initval1); initval1 := resume (co2, add1 (initval1)); returncont (initval1) end ); co2 := makecoroutine ( proc (initval2) begin print (2); print (initval2); initval2 := resume (co1, add1 (initval2)); print (2); print (initval2); resume (co1, add1 (initval2)) end ); co1(33) end => [0 environments] --> --> example() expanded to: ['app', ['varref', 'example'], []] => [1] [33] [2] [34] [1] [35] [2] [36] 37 [93 environments] -->