To show how this rule is followed,
figure
[3.6]
illustrates the environment structure created by evaluating the
expression
square(5)
in the
program
environment, where
square is the
function
generated in
figure
[3.4].
Applying the
function
results in the creation of a new environment, labeled E1 in the figure, that
begins with a frame in which
x, the
parameter for the
function,
is bound to the argument 5.
Note that name
x in environment E1 is
followed by a colon with no equal sign, which indicates
that the parameter
x is treated as a
variable.
The pointer leading upward from this frame shows that the
frame's enclosing environment is the
program
environment. The
program
environment is chosen here, because this is the environment that is
indicated as part of the
square
function
object. Within E1, we evaluate the body of the
function,
return x * x;.
Since the value of
x in E1 is 5, the result is
5 * 5,
or 25.
この規則がどのように適用されるかを示すために、
図
[3.6]
に、
square(5)
という式を
プログラム
環境で評価したときに生成される環境構造を示します。ここで
square は
図
[3.4]
で生成された
関数
です。
この
関数
を適用すると、図で E1 と名付けられた新しい環境が作成されます。この環境は、
関数
の
パラメータ
x が引数 5 に束縛されたフレームから始まります。
環境 E1 における名前
x の後に等号のないコロンが付いていることに注目してください。これはパラメータ
x が変数として扱われることを示しています。
このフレームから上向きに伸びるポインタは、フレームの外側の環境が
プログラム
環境であることを示しています。
プログラム
環境が選ばれるのは、それが
square
関数
オブジェクトの一部として示されている環境だからです。E1 の中で、
関数
の本体
return x * x;
を評価します。
E1 での
x の値は 5 なので、結果は
5 * 5、
すなわち 25 です。