正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12.2.1 Okay, we are ready to start looking at our rules for evaluation inName-rule our new model, especially to how environments are created and manipulated as part of the evaluation process The simplest possible expressions are just numbers. These are self-evaluating which means that their value is just their value independent of the environment The first interesting rule comes with names. We have a way of dealing with evaluation of names, our simplest kind of primitive, and that rule should tell us how to get the value ated with a variabl 6001Sc Slide 12.2.2 A name X evaluated in environment E gi\ The rule is straightforward, but quite mechanistic. A name X the value of x in the first frame of e whe is bound evaluated in an environment e gives back the value of X in the first frame of e in which there is a binding for X. Remember, an environment is a sequence of frames, so we will start in the first frame of the lent, looking for a binding of that name. We will continue up the chain of frames until we find the first such binding, in which case we return the value associated with that binding Slide 12.2.3 Name-rule So here are our example environments from before. We will A name X evaluated in environment E gives call the top level environment, the global environment, or our the value of x in the first frame of e where x is bound stopgap environment Environment El has its own frame, and inherits as its enclosing environment, the global environment z:10 Slide 12. 2.4 A name x evaluated in environment E gives We can now talk about the value of a variable with respect to the value of x in the first frame of e where x is bound an environment; in fact we should always talk about the value I o=> 10 2In=>10 *Ie=> 15 of any expression with respect to some environment. For example, we can ask for the value of the variable z with respect to the global environment. Notice the notation we use for this namely the expression, then a i to indicate the evaluation with respect to some environment, then a subscript to denote the actual environment. Note that normally we will evaluate expressions with respect to the global environment, since that is where we interact with the Scheme system. If I type in a the expression to the Scheme interpreter, I am interacting with6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.2.1 Okay, we are ready to start looking at our rules for evaluation in our new model, especially to how environments are created and manipulated as part of the evaluation process. The simplest possible expressions are just numbers. These are self-evaluating which means that their value is just their value, independent of the environment. The first interesting rule comes with names. We have a way of dealing with evaluation of names, our simplest kind of primitive, and that rule should tell us how to get the value associated with a variable. Slide 12.2.2 The rule is straightforward, but quite mechanistic. A name X evaluated in an environment E gives back the value of X in the first frame of E in which there is a binding for X. Remember, an environment is a sequence of frames, so we will start in the first frame of the environment, looking for a binding of that name. We will continue up the chain of frames until we find the first such binding, in which case we return the value associated with that binding. Slide 12.2.3 So here are our example environments from before. We will call the top level environment, the global environment, or our stopgap environment. Environment E1 has its own frame, and inherits as its enclosing environment, the global environment. Slide 12.2.4 We can now talk about the value of a variable with respect to an environment; in fact we should always talk about the value of any expression with respect to some environment. For example, we can ask for the value of the variable z with respect to the global environment. Notice the notation we use for this, namely the expression, then a | to indicate the evaluation with respect to some environment, then a subscript to denote the actual environment. Note that normally we will evaluate expressions with respect to the global environment, since that is where we interact with the Scheme system. If I type in an expression to the Scheme interpreter, I am interacting with the
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有