The environment model as presented so far focuses on how functions can refer
to their parameters, locally declared names, and names that are declared
outside the function. We achieve this by evaluating statements and expressions
with respect to a current environment. It does not specify how
we keep track of environments as computation proceeds. For example, when we
evaluate an expression f(x) + y, we
need to evaluate x in the current
environment, establish as the new current environment the environment of
f extended by a binding of its
parameter to the value of x, and
evaluate the body of f in this
extended environment. But what environment should we use for evaluating
y after
f returns?
In this section, we extend the
これまで紹介してきた環境モデルは、関数がそのパラメータ、ローカルに宣言された名前、および関数の外部で宣言された名前をどのように参照できるかに焦点を当てていました。これは、文や式を現在の環境に基づいて評価することで実現しています。しかし、計算が進む中で環境をどのように追跡するかは規定していません。例えば、式 f(x) + y を評価するとき、まず現在の環境で x を評価し、f の環境にそのパラメータと x の値の束縛を追加した新しい環境を現在の環境として設定し、この拡張された環境で f の本体を評価する必要があります。しかし、f から戻った後、y の評価にはどの環境を使うべきでしょうか?
このセクションでは、
Exercise
[3.8] shows that the presence of
assignments makes the result of a program depend on the order in which
the operands of an operator combination are evaluated. To remove
ambiguities that arise from this, the JavaScript standard specifies
left-to-right evaluation of operands.
As an example, consider the evaluation of the arithmetic expression statement
練習問題
[3.8]では、代入があるとプログラムの結果が演算子の組み合わせのオペランドの評価順序に依存することを示しました。これによる曖昧さを取り除くために、JavaScript の標準ではオペランドの左から右への評価を規定しています。
例として、次の算術式の式文の評価を考えましょう。
The expression is decomposed into its operands
1 and
2 * 3, followed by the
instruction to add their results.
この式は、オペランドである
1 と
2 * 3 に分解され、続いてそれらの結果を加算する命令が実行されます。