正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 15.7.10 Implementation of lambda* Eval-lambda starts with the same tree structure as an (va1'( anda·(x*)(1口xx*))cE eval-lambda'(lambda*(x*)(plus*** x*))GE,I argument, plus some pointer to the global environment(GE) What does it do? It walks down the tree structure of the first argument, and grab the arguments(that's the cadr). Similarly, walk down the tree structure and grab the body(thats the caddr)(note that we are assuming there is only one expression in the body In this case, the cadr will return the list(x*)and the caddo will return the list(plus* x* x*). let me stress agai that we are simply getting these as tree structure; there is no glue them together using make-compound Valuation yet. Having acquired those two structures, we then Slide 15.7.11 Implementation of lambda* So the evaluation reduces to this expression. This is simply Keval(l anbda* (x*)(plus.x*I*))GE) using our constructor to glue these pieces together, and in this (eval-lambda '(lambda* (Et*)(plus* x**))GE) case that converts to this form make-compound +(x*).(plus* x* x*)GE Implementation of lambda* Slide 15.7.12 eva1(1 anda·(x)(p1unx请x*))cE and thus we are down to a basic primitive. We are going to teval-lambda' (ambdat (x+)(plust x+ x+) Ge, construct a new list structure, with a type tag, a list of make- compound《x*)·(p1us★x*x*)GE parameters, a body and the environment in which this (list 'compound ' (**)1(plus*****)GE) l ambda* expression was created6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 15.7.10 Eval-lambda starts with the same tree structure as an argument, plus some pointer to the global environment (GE). What does it do? It walks down the tree structure of the first argument, and grab the arguments (that's the cadr). Similarly, walk down the tree structure and grab the body (that's the caddr) (note that we are assuming there is only one expression in the body). In this case, the cadr will return the list (x*) and the caddr will return the list (plus* x* x*). Let me stress again that we are simply getting these as tree structure; there is no evaluation yet. Having acquired those two structures, we then glue them together using make-compound. Slide 15.7.11 So the evaluation reduces to this expression. This is simply using our constructor to glue these pieces together, and in this case that converts to this form.... Slide 15.7.12 ... and thus we are down to a basic primitive. We are going to construct a new list structure, with a type tag, a list of parameters, a body and the environment in which this lambda* expression was created
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有