Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Common Lisp
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Determiners of scope=== The circumstances which determine scope in Common Lisp include: * the location of a reference within an expression. If it's the leftmost position of a compound, it refers to a special operator or a macro or function binding, otherwise to a variable binding or something else. * the kind of expression in which the reference takes place. For instance, <code>(go x)</code> means transfer control to label <code>x</code>, whereas <code>(print x)</code> refers to the variable <code>x</code>. Both scopes of <code>x</code> can be active in the same region of program text, since tagbody labels are in a separate namespace from variable names. A special form or macro form has complete control over the meanings of all symbols in its syntax. For instance, in <code>(defclass x (a b) ())</code>, a class definition, the <code>(a b)</code> is a list of base classes, so these names are looked up in the space of class names, and <code>x</code> isn't a reference to an existing binding, but the name of a new class being derived from <code>a</code> and <code>b</code>. These facts emerge purely from the semantics of <code>defclass</code>. The only generic fact about this expression is that <code>defclass</code> refers to a macro binding; everything else is up to <code>defclass</code>. * the location of the reference within the program text. For instance, if a reference to variable <code>x</code> is enclosed in a binding construct such as a [[let expression|<code>let</code>]] which defines a binding for <code>x</code>, then the reference is in the scope created by that binding. * for a variable reference, whether or not a variable symbol has been, locally or globally, declared special. This determines whether the reference is resolved within a lexical environment, or within a dynamic environment. * the specific instance of the environment in which the reference is resolved. An environment is a run-time dictionary which maps symbols to bindings. Each kind of reference uses its own kind of environment. References to lexical variables are resolved in a lexical environment, et cetera. More than one environment can be associated with the same reference. For instance, thanks to recursion or the use of multiple threads, multiple activations of the same function can exist at the same time. These activations share the same program text, but each has its own lexical environment instance. To understand what a symbol refers to, the Common Lisp programmer must know what kind of reference is being expressed, what kind of scope it uses if it is a variable reference (dynamic versus lexical scope), and also the run-time situation: in what environment is the reference resolved, where was the binding introduced into the environment, et cetera.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)