根据SICP的评估环境模型进行词汇和动态范围界定 [英] Lexical vs dynamic scoping in terms of SICP's Environment Model of Evaluation
问题描述
在
根据每次应用功能时,都会创建一个新框架(用E1
至E4
标记),该框架代表符号和值之间的一组绑定.当符号未绑定到框架中时,将查询该框架的封闭环境以绑定该特定符号.
Each time a function is applied, a new frame is created (labeled by E1
through E4
) which represents a set of bindings between symbols and values. When a symbol is not bound in a frame, that frame's enclosing environment is queried for a binding of that particular symbol.
关于此图的有趣之处在于,所有由E
标记的帧都包含在全局环境中.文字解释说这是因为这些功能是在全局环境中定义的,但并未对此问题进行详细说明:
The interesting thing about this diagram is that all the frames labelled by E
is contained in the global environment. The text explains that this is because the functions was defined in the global environment, but does not elaborate on the issue:
请注意,由
square
创建的每个框架都指向全局环境,因为这是square
过程对象指示的环境.
Notice that each frame created by
square
points to the global environment, since this is the environment indicated by thesquare
procedure object.
如果取而代之的是在调用该函数的环境中包含框架,例如E3
包含在E2
中,而E2
包含在E1
中,那将是动态范围语言的有效模型作品?另外,由于Scheme在词法范围内,图中的框架具有相同的父"环境吗?
If instead frames where contained in the environment that the function was called in, say E3
was contained in E2
which in turn was contained in E1
, would that be a valid model of how a dynamically scoped language works? Also, is the way that the frames in the diagram have the same 'parent' environment because Scheme is lexically scoped?
推荐答案
两个问题的答案都是是. SICP的这一章在不实际使用术语的情况下解释了词法范围.如您所描述的那样更改评估机制将创建一个动态范围的模型.
The answer to both questions is yes. That chapter of SICP is explaining lexical scope without actually using the term. Changing the evaluation mechanism as you describe would create a dynamically-scoped model.
这篇关于根据SICP的评估环境模型进行词汇和动态范围界定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!