When the
assignment
is executed, the binding of
balance in E1 is
changed. At the completion of the call to
W1,
balance is 50,
and the frame that contains
balance is still
pointed to by the
function
object
W1. The frame that binds
amount (in which we executed the code that
changed
balance) is no longer relevant, since
the
function
call that constructed it has terminated, and there are no pointers to that
frame from other parts of the environment. The next time
W1 is called, this will build a new frame that
binds
amount and whose enclosing environment is
E1. We see that E1 serves as the
place
that holds the local
state variable for the
function
object
W1.
Figure
[3.18]
shows the situation after the call to
W1.
代入
が実行されると、E1 における
balance の束縛が変更されます。
W1 の呼び出しが完了した時点で、
balance は 50 になっており、
balance を含むフレームは依然として
関数
オブジェクト
W1 から指されています。
amount を束縛するフレーム(
balance を変更したコードを実行したフレーム)は、それを構築した
関数
呼び出しが終了し、環境の他の部分からそのフレームへのポインタもないため、もはや関係ありません。次に
W1 が呼び出されるときには、
amount を束縛する新しいフレームが構築され、その外側の環境は E1 になります。E1 が
関数
オブジェクト
W1 のローカル状態変数を保持する
場所
として機能していることがわかります。
図
[3.18]
に、
W1 の呼び出し後の状況を示します。