<< Previous exercise (5.30) | Index | Next exercise (5.32) >>
(f 'x 'y) => all the saves are not necessary. ((f) 'x 'y) => not necessary too, although (f) is a compound-procedure, it will change the env register to the status where f is defined, but it will not affect the quoted 'x and 'y. (f (g 'x) y) => proc and argl are necessary, save env before eval (g 'x) is necessary too, it will change the env register and y will be affected. (f (g 'x) 'y) => proc and argl is necessary, but no need to save env before eval (g 'x) cause 'y is quoted, it will not fetch any value in the env, and env register will be reset to the status where f is defined
I think this matches Perry's answer
┌──────────────────┬───────────┬───────────┬───────────┬───────────┐ │ │ operator │ operands │ operands │ op'd seq │ │ │ env │ env │ argl │ proc │ ├──────────────────┼───────────┼───────────┼───────────┼───────────┤ │ 1: (f 'x 'y) │ eliminate │ eliminate │ eliminate │ eliminate │ ├──────────────────┼───────────┼───────────┼───────────┼───────────┤ │ 2: ((f) 'x 'y) │ eliminate │ eliminate │ eliminate │ eliminate │ ├──────────────────┼───────────┼───────────┼───────────┼───────────┤ │ 3: (f (g 'x) y) │ eliminate │ │ │ │ ├──────────────────┼───────────┼───────────┼───────────┼───────────┤ │ 4: (f (g 'x) 'y) │ eliminate │ eliminate │ │ │ └──────────────────┴───────────┴───────────┴───────────┴───────────┘ Operator Env ============ Only need to save/restore if env could change in evaluating the operator and we need env to evaluate the operands. In the case of 2: the environment would be changed in evaluating (f) but the environment is not needed to evaluate symbols 'x and 'y. Operands Env ============ Only need to save/restore between operands if there's an operand expression that might change env and a subsequent operand that needs env for variable lookup. This is only the case for 3:. Operands Argl ============= We need to save/restore argl anytime there's an operand that might change the value of argl. That's 3: and 4:. Operaand Sequence Proc ====================== We need to save/restore proc if there's any operand that might change the value of proc. That's 3: and 4:.
meteorgan