Re: What Does Lexical Mean?



Nick Mudge <mudgen@xxxxxxxxx> 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@xxxxxxxx>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

.



Relevant Pages

  • Re: Reintroducing fish, the friendly interactive shell
    ... Fish supports universal variables, which are variables whose value is ... Universal variables have the outermost scope, ... Universal variables make it much more practical to use environment ... Can you specify the normal behaviour of shell? ...
    (comp.unix.shell)
  • Re: A question about lexical binding
    ... from SICP uses a deep binding environment. ... However, deep binding has the problem that depending upon the caller, ... Whether you get lexical or dynamic scope depends on how you terminate the ... toplevel frame, you have lexical references; ...
    (comp.lang.lisp)
  • Exception using Isolated Storage in ASP.NET on a hosted server
    ... I'm getting the following exception on the hosted environment: ... scope) at ... scope, Type domainEvidenceType, Type assemblyEvidenceType) at ...
    (microsoft.public.dotnet.framework)
  • Re: Closures, was Re: What does Tcl lack?
    ... > understand that the execution environment can be different of the ... I think you're oversimplifying what happens in Tcl. ... can also use "global x" to indicate that the x is in the global scope, ... lexically scoped languages tend to ...
    (comp.lang.tcl)
  • Re: third believe system Re: Does Searles "Chinese Room" argument imply that consciousness is non
    ... Human analyzing this process will have to _import_ the context ... We have no causal link to events that happened 1 ... The fact that our brain doesn't have the resolution and sensors to detect ... So an environment full of other intelligent agents ...
    (comp.ai.philosophy)