Nick Mudge <mudgen@gmail.com> wrote:
+---------------
| I've looked around on the Internet for a good definition of what
| exactly "lexical" means in the context of programming, but I have not
| found one, or at least it is not clear.
+---------------
Well, the first & most basic thing is that the adjective "lexical"
literally means "of or relating to words" or more generally, to text.
E.g., "lexical analysis" is the process of reading a text and
breaking it up into its constituent "lexical tokens" (sometimes
called just "tokens") which then are handed to the "syntactic parser"
(or just "parser") for "syntax analysis". You can Google for those
terms yourself to find out more.
But from your question I suspect you're really asking about
"lexical variables" and "lexical scope", sometimes [as in the
following URL] also called "static scope", see:
http://en.wikipedia.org/wiki/Scope_%28programming%29
especially the "History" paragraph.
You can also look up most of these terms in the CLHS Glossary:
http://alu.org/HyperSpec/Body/sec_26-1.html>
The story begins with the notion of a "scope":
http://alu.org/HyperSpec/Body/glo_s.html#scope
scope n. the structural or textual region of code in which
references to an object, a binding, an exit point, a tag,
or an environment (usually by name) can occur.
Something is "lexically scoped" if you can determine all of the
places where that something is "in scope", that is, has a certain
value, simply by examining the source text -- you don't have to
actually run the program. In Common Lisp, it's defined this way:
http://alu.org/HyperSpec/Body/glo_l.html#lexical_scope
lexical scope n. scope that is limited to a spatial or textual
region within the establishing form. ...
Said another way, with "dynamic binding" [see the CLHS], to know
what a (dynamic) variable is going to contain you have to know the
actual runtime (dynamic) history of execution up until the place
*and* exact time you're asking the question. But with lexical
scoping, you can know just by looking at the program text [lexicum].
Having absorbed that, you now probably have enough context to go
read this entire section of the CLHS [although skip or skim the
subsection on "Environment Objects" until later in your studies]:
http://alu.org/HyperSpec/Body/sec_3-1-1.html
3.1.1 Introduction to Environments
A binding is ... [trimmed].
An environment is ... [trimmed].
Bindings in an environment are partitioned into namespaces.
...
3.1.1.1 The Global Environment
3.1.1.2 Dynamic Environments
3.1.1.3 Lexical Environments
3.1.1.4 Environment Objects
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607