From: thelifter
Subject: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <b295356a.0211190817.4f265687@posting.google.com>
Hello,

after some postings in the thread "Idiot's guide to special variables
take 2", I  think I have finally understood variables and symbols in
Lisp. I will try to explain them myself, please correct me if
necessary.

1. A Lisp program is a list, which may also include symbols.

2. A variable is an "abstract" object which is able to hold a value.
The program can then store and retrieve that value. Variables don't
appear in the Lisp program explicitly, only symbols. Some symbols may
denote variables, in that case the symbol is the name of the variable.

3. If the symbol is refering to a lexical variable the value of that
variable will be stored/retrieved from the lexical environment.

4. If the symbol is refering to a dynamic variable the value of that
variable will be stored/retrieved from the value cell of the symbol.
In fact this is the only reason why the symbol needs a value cell at
all(for the sake of dynamic variables).

Was that correct now?
Can I now change my name back from theIdiot to theLifter? :))

Thanks for reading this!

From: Erann Gat
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <gat-1911021212080001@k-137-79-50-101.jpl.nasa.gov>
In article <····························@posting.google.com>,
·········@gmx.net (thelifter) wrote:

> 4. If the symbol is refering to a dynamic variable the value of that
> variable will be stored/retrieved from the value cell of the symbol.

Not quite.  This model gets you into trouble in multi-threaded
environments.  A better model is that if the symbol is referring to a
dynamic variable then the value gets looked up in the dynamic environment,
and each thread has its own dynamic environment.

E.
From: Kent M Pitman
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <sfwof8jyaqb.fsf@shell01.TheWorld.com>
···@jpl.nasa.gov (Erann Gat) writes:

> In article <····························@posting.google.com>,
> ·········@gmx.net (thelifter) wrote:
> 
> > 4. If the symbol is refering to a dynamic variable the value of that
> > variable will be stored/retrieved from the value cell of the symbol.
> 
> Not quite.  This model gets you into trouble in multi-threaded
> environments.  A better model is that if the symbol is referring to a
> dynamic variable then the value gets looked up in the dynamic environment,
> and each thread has its own dynamic environment.

Of course, ANSI CL does not address multi-threading.

And an implementatio which offers such could just say that value cells
are bound per-thread.  How this is accomplished is up to the implementation
to reveal or not, but ANSI CL is deliberately vague on the matter of
implementation/layout exactly in order to permit implementations to choose
a specific implementation that suits them.

The "value cell" terminology is traditional and does have to be explained.
You can't quite get rid of it by simply not mentioning it.  You have to
instead explain what a value cell _is_ in a modified environment.
From: Erann Gat
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <gat-2111020852320001@192.168.1.51>
In article <···············@shell01.TheWorld.com>, Kent M Pitman
<······@world.std.com> wrote:

> ···@jpl.nasa.gov (Erann Gat) writes:
> 
> > In article <····························@posting.google.com>,
> > ·········@gmx.net (thelifter) wrote:
> > 
> > > 4. If the symbol is refering to a dynamic variable the value of that
> > > variable will be stored/retrieved from the value cell of the symbol.
> > 
> > Not quite.  This model gets you into trouble in multi-threaded
> > environments.  A better model is that if the symbol is referring to a
> > dynamic variable then the value gets looked up in the dynamic environment,
> > and each thread has its own dynamic environment.
> 
> Of course, ANSI CL does not address multi-threading.

Right.  This leads to pedagogical problems...

> The "value cell" terminology is traditional and does have to be explained.
> You can't quite get rid of it by simply not mentioning it.  You have to
> instead explain what a value cell _is_ in a modified environment.

The problem is not with the term "value cell" per se.  The problem is in
the OP's use of the phrase "*the* value cell of the symbol" implying
through the use of the definite article "the" that a symbol has exactly
one value cell (e.g. a model of a symbol where a symbol is a structure
with a value slot).  The standard, by not addressing threads, does nothing
to dispell this model, but it fails in a multithreaded environment.

E.
From: Kent M Pitman
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <sfwof8iwe2k.fsf@shell01.TheWorld.com>
···@jpl.nasa.gov (Erann Gat) writes:

> The problem is not with the term "value cell" per se.  The problem is in
> the OP's use of the phrase "*the* value cell of the symbol" implying
> through the use of the definite article "the" that a symbol has exactly
> one value cell (e.g. a model of a symbol where a symbol is a structure
> with a value slot).  The standard, by not addressing threads, does nothing
> to dispell this model, but it fails in a multithreaded environment.

The term "the lexical binding of the variable" is used without implying
uniqueness.  Even excluding multiprocessing, the definite article is used
to keep incarnations of a lexical variable straight.  The fact is (and,
incidentally, there are more than one facts involved in this discussion,
so don't be confused by my use of "the" in this sentence) that the standard
expects you to sort out the nuances of natural language in a way that means
that you shouldn't be overly confused by "the value cell" even if there's
more than one...  

So I do take your point that it's an opportunity to be confused, since
confusion obviously can burst out nearly anywhere, but seriously I think
that if you find someone fussing over an ill-placed "the", it's often 
a reason to tell the person to "mellow out"...  Yes, if we had infinite
time and money it might have been a thing to care about, but in the meantime,
world resources being what they are, the burden is on the reader to get
past this one.
From: Erann Gat
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <gat-2211020029080001@192.168.1.51>
In article <···············@shell01.TheWorld.com>, Kent M Pitman
<······@world.std.com> wrote:

> I think
> that if you find someone fussing over an ill-placed "the", it's often 
> a reason to tell the person to "mellow out"...

I'm not fussing over an ill-placed "the."  I'm reading an ill-placed "the"
as evidence of possible confusion on the part of the writer.  There's a
difference.

Let's recall the passage in question:

> 4. If the symbol is refering to a dynamic variable the value of that
> variable will be stored/retrieved from the value cell of the symbol.
> In fact this is the only reason why the symbol needs a value cell at
> all(for the sake of dynamic variables).

The only way to really find out of the OP was confused is to ask him. 
(Lifter, are you following this?)  But the reason I thought he might be
confused is because I myself was confused about this for years, and the
above passage is exactly how I would have described things during my
period of confusion.  (In fact, it *is* exactly how I did describe things
in the first edition of the "Idiot's guide".)  I see evidence of similar
confusion pop up on a more or less continual basis.

E.

P.S. One way to test yourself if you understand how things really work is
to see if you understand why

(let ((x 1))
  (declare (special x))
  ...

is not the same as

(let ((temp x))
  (unwind-protect
    (progn (setf (symbol-value 'x) 1) ...)
    (setf (symbol-value 'x) temp)))
From: Joe Marshall
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <vg2tnwk5.fsf@ccs.neu.edu>
·········@gmx.net (thelifter) writes:

> 4. If the symbol is refering to a dynamic variable the value of that
> variable will be stored/retrieved from the value cell of the symbol.
> In fact this is the only reason why the symbol needs a value cell at
> all (for the sake of dynamic variables).

And for EVAL.
From: Kent M Pitman
Subject: Re: Understanding variables and symbols(from the idiots point of view). Please read and comment.
Date: 
Message-ID: <sfwlm3pz4lo.fsf@shell01.TheWorld.com>
·········@gmx.net (thelifter) writes:

> after some postings in the thread "Idiot's guide to special variables
> take 2", I  think I have finally understood variables and symbols in
> Lisp. I will try to explain them myself, please correct me if
> necessary.
> 
> 1. A Lisp program is a list, which may also include symbols.
> 
> 2. A variable is an "abstract" object which is able to hold a value.
> The program can then store and retrieve that value. Variables don't
> appear in the Lisp program explicitly, only symbols. Some symbols may
> denote variables, in that case the symbol is the name of the variable.
> 
> 3. If the symbol is refering to a lexical variable the value of that
> variable will be stored/retrieved from the lexical environment.
> 
> 4. If the symbol is refering to a dynamic variable the value of that
> variable will be stored/retrieved from the value cell of the symbol.
> In fact this is the only reason why the symbol needs a value cell at
> all(for the sake of dynamic variables).
> 
> Was that correct now?

This is largely correct except I would point out that a symbol "needing a
value cell" might misleadingly suggest that one is required to be manifestly
allocated even when unused.  Value cells, like function cells, could be
demand-allocated and so the having or not having them is not really an issue.
I might write 4 instead as something more like:

 If the symbol is referring to a dynamic variable, then the symbol is
 said to have a value cell, the contents of which are said to be the 
 value of the dynamic variable.

> Can I now change my name back from theIdiot to theLifter? :))

I'm only competent to answer the easy questions.  Sorry.