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

Info icon This 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
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern