Next: , Previous: , Up: 変数   [Contents][Index]


12.10 変数のバインディングのスコーピングルール

ある変数にたいするローカルバインディングを作成するとき、そのバインディングはプログラムの限られた一部だけに効果をもちます(ローカル変数を参照)。このセクションでは、これが正確には何を意味するかについて説明します。

ローカルバインディングはそれぞれ、個別にスコープ(scope: 範囲という意味)エクステント(extent: これも範囲を意味する)をもちます。スコープはそのバインディングにアクセスできるのが、テキストのソースコードのどこ(where)であるかを示します。エクステントはプログラムの実行中に、そのバインディングが存在するのがいつ(when)であるかを示します。

For historical reasons, there are two dialects of Emacs Lisp, selected via the lexical-binding buffer-local variable. In the modern Emacs Lisp dialect, local bindings are lexical by default. A lexical binding has lexical scope, meaning that any reference to the variable must be located textually within the binding construct10. It also has indefinite extent, meaning that under some circumstances the binding can live on even after the binding construct has finished executing, by means of objects called closures.

Local bindings can also be dynamic, which they always are in the old Emacs Lisp dialect and optionally in the modern dialect. A dynamic binding has dynamic scope, meaning that any part of the program can potentially access the variable binding. It also has dynamic extent, meaning that the binding lasts only while the binding construct (such as the body of a let form) is being executed.

The old dynamic-only Emacs Lisp dialect is still the default in code loaded or evaluated from Lisp files that lack a dialect declaration. Eventually the modern dialect will be made the default. All Lisp files should declare the dialect used to ensure that they keep working correctly in the future.

The following subsections describe lexical binding and dynamic binding in greater detail, and how to enable lexical binding in Emacs Lisp programs.


Footnotes

(10)

With some exceptions; for instance, a lexical binding can also be accessed from the Lisp debugger.


Next: バッファーローカル変数, Previous: 変数が変更されたときに実行される関数。, Up: 変数   [Contents][Index]

This page has generated for branch:master, commit:762705fb24fd90db318f2e51c1e762452d26f7e2 to check Japanese translation.