Difference between revisions of "Lexical scope"

From WikEmacs
Jump to navigation Jump to search
m
m
 
Line 1: Line 1:
'''Lexical scope''' in general is the idea that:
+
[[Emacs_Lisp#Scope|'''Lexical scope''']] in general is the idea that:
  
 
*an identifier at a particular place in a program always refers to the same variable location — where “always” means “every time that the containing expression is executed”, and that
 
*an identifier at a particular place in a program always refers to the same variable location — where “always” means “every time that the containing expression is executed”, and that
Line 5: Line 5:
  
 
In practice, lexical scoping is the norm for most programming languages, and probably corresponds to what you would intuitively consider to be “normal”. You may even be wondering how the situation could possibly — and usefully — be otherwise.
 
In practice, lexical scoping is the norm for most programming languages, and probably corresponds to what you would intuitively consider to be “normal”. You may even be wondering how the situation could possibly — and usefully — be otherwise.
 
Put
 
<source lang="lisp">
 
;;; -*- lexical-binding: t; -*-
 
</source>
 
at the top of a file to enable lexical scope for that file.
 

Latest revision as of 19:19, 28 October 2015

Lexical scope in general is the idea that:

  • an identifier at a particular place in a program always refers to the same variable location — where “always” means “every time that the containing expression is executed”, and that
  • the variable location to which it refers can be determined by static examination of the source code context in which that identifier appears, without having to consider the flow of execution through the program as a whole.

In practice, lexical scoping is the norm for most programming languages, and probably corresponds to what you would intuitively consider to be “normal”. You may even be wondering how the situation could possibly — and usefully — be otherwise.