hw13 - Homework 13 solutions: 4.22 LET in analyzing...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Homework 13 solutions: 4.22 LET in analyzing evaluator This is easy, given the hint about 4.6. We don't have to change the procedure LET->COMBINATION we wrote for that exercise entirely with the expression, and not with the values of variables, all of its work can be done in the analysis phase. All we do is change this COND clause in EVAL: ((let? exp) (eval (let->combination exp) env)) to this COND clause in ANALYZE: ((let? exp) (analyze (let->combination exp))) 4.23 Efficiency of analyze-sequence For a sequence with just one expression, the book's version does the following analysis: First, the body of analyze-sequence is the LET. Suppose that the result of analyzing the one expression is PROC. Then the variable PROCS will have as its value a list whose only element is PROC. That's not null, so (still in the analysis part) we call (LOOP PROC '()). In LOOP, since (in this case) REST-PROCS is null, LOOP just returns PROC. So if the analysis of EXP gives PROC, then the analysis of (BEGIN EXP) also gives PROC. In the same one-expression case, Alyssa's version returns (lambda (env) (execute-sequence (list PROC) env)) So every time this execution procedure is called, execute-sequence will check that (cdr procs) is empty, which it is, and then calls PROC with the environment as its argument. This test of (null? (cdr procs)) is done for every execution, whereas in the book's version it was done just once. How about the two-expression case. Suppose that the analysis of EXP1 gives PROC1, and the anaylsis of EXP2 gives PROC2. The book's version will call, in effect, (loop PROC1 (list PROC2)). This in turn calls (sequentially PROC1 PROC2), which returns (lambda (env) (PROC1 env) (PROC2 env))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

hw13 - Homework 13 solutions: 4.22 LET in analyzing...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online