Erann Gat <email@example.com> wrote:
| Mark Conrad <firstname.lastname@example.org> wrote:
| > I feel that if I could understand the subtle differences between the
| > meanings of "binding" and "value", that might have something to do with
| > figuring out why the above example code above works as it does.
| Try this:
| A binding is a memory location.
| A value is what is stored in that memory location.
Actually, here's one area where IMHO the Scheme folk seem to have the
terminology about right. From R5RS 3.1 "Variables, syntactic keywords,
An identifier may name a type of syntax, or it may name a
location where a value can be stored. ... An identifier that
names a location is called a variable and is said to be bound to
that location. The set of all visible bindings in effect at some
point in a program is known as the environment in effect at that
point. The value stored in the location to which a variable is
bound is called the variable's value.
Note that they also warn:
By abuse of terminology, the variable is sometimes said to name
the value or to be bound to the value. This is not quite accurate,
but confusion rarely results from this practice.
Except in discussions like this thread... ;-} ;-}
| So what is going on in the example above is:
| (let ((x 1)) ; Establish a binding (i.e. a memory location) for X.
Actually, *three* things logically happen here [assuming a lexical binding]:
1. A new location is allocated;
2. The variable "x" is bound to (caused to name) that location; and
3. The location is initialized with the value "1".
In CL terms, one may treat "location" as equivalent to "place", so that
one may use a bound variable as the destination of a SETQ or SETF.
| (defun x () x) ; Return the value in the binding (i.e. the memory
| ; location) established above
| (defun set-x (new) ; Change the value in the binding (the memory location)
| (setf x new)) ; of X to NEW
Close enough, I guess, but if I was being picky I'd say "return/change
the contents of the location the variable 'x' is bound to".
Rob Warnock, PP-ASEL-IA <email@example.com>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607