On 2012-06-10, Pascal J. Bourguignon <
p...@informatimago.com> wrote:
> Kaz Kylheku <
k...@kylheku.com> writes:
>
>> On 2012-06-10, Pascal J. Bourguignon <
p...@informatimago.com> wrote:
>>> Kaz Kylheku <
k...@kylheku.com> writes:
>>>
>>>> On 2012-06-10, Pascal J. Bourguignon <
p...@informatimago.com> wrote:
>>>>> Well,
>>>>>
>>>>> (defvar x) == (declaim (special x))
>>>>>
>>>>> and:
>>>>>
>>>>> (defvar x) == (declaim (special x))
>>>>> (setf x 42) == (setf (symbol-value 'x) 42)
>>>>>
>>>>> so we could specify that without a definition for x,
>>>>>
>>>>> (setf x 42) == (setf (symbol-value 'x) 42)
>>>>
>>>> If x doesn't exist, then basically we are equating two undefined behaviors.
>>>
>>> No. (setf (symbol-value 'x) 42) is always well defined.
>>
>> That's not what I'm reading in the CLHS. The specification for symbol-value
>> clearly states that the input symbol "must have a value", and that it "[s]hould
>> signal unbound-variable if symbol is unbound and an attempt is made to read its
>> value." Furthermore, "[N]o such error is signaled on an attempt to write its
>> value." Note how it doesn't simply say that writing is a well-defined
>> operation, only that it is undiagnosed, and that it is only an attempt.
>>
>> If you want to regard that as a defect, I'm with you.
>
> You're confusing the specification of the reader with that of the
> writer. Here I'm using the writer.
>
> Just _read_ the CLHS!
The reader and writer are not separately specified.
Accessor SYMBOL-VALUE
Syntax:
symbol-value symbol => value
(setf (symbol-value symbol) new-value)
Arguments and Values:
symbol---a symbol that must have a value.
value, new-value---an object.
Where does it say that the symbol must have a value when the
reader is being used, but not when the writer is being used?
Are we not looking at the same document?
> Should signal unbound-variable if symbol is unbound and an attempt
> is made to read its value. (No such error is signaled on an attempt
> to write its value.)
Why would an operation which is expected to succeed unconditionally be
described as an "attempt"? Why is not written that if the symbol is unbound,
writing the value is okay and makes it bound?
If writing to a symbol was unconditionally okay, the above wording would be a
very, very poor way document that requirement.
> Notice that after calling (setf symbol-value), the symbol is bound, and
> you can call symbol-value.
I'm afraid this is a hack outside of the standard, just like SETF-ing an
undefined variable.
If the symbol is bound, and then later that symbol is evaluated as a form,
what kind of variable is it? dynamic or lexical?
If a form is a symbol that is not a symbol macro, then it is the name of a
variable, and the value of that variable is returned. There are three kinds of
variables: lexical variables, dynamic variables, and constant variables. A
variable can store one object. The main operations on a variable are to read[1]
and to write[1] its value.
An error of type unbound-variable should be signaled if an unbound variable is referenced.
[3.1.2.1.1 Symbols as Forms]
If you think it's dynamic, then how did it get that way? Neither of the two
conditions for making a dynamic variable have been met.
3.1.2.1.1.2 Dynamic Variables
A variable is a dynamic variable if one of the following conditions hold:
* It is locally declared or globally proclaimed special.
* It occurs textually within a form that creates a dynamic binding for a
variable of the same name, and the binding is not shadowed[2] by a form
that creates a lexical binding of the same variable name.
[...]
A dynamic variable is unbound unless and until explicitly assigned a value,
except for those variables whose initial value is defined in this
specification or by an implementation.
I think even this is not conforming:
(defvar foo) ;; no initial value
(setf (symbol-value 'foo) 42) ;; oops, "symbol must have value" requirement violated
The definition of symbol-value does not say that it's okay to set
an unbound symbol if that symbol is a dynamic variable with no value.
According to the definition of a dynamic variable above, the only way an
unbound dynamic variable can acquire a value is by assignment,
and (setf symbol-value) is not an assignment.
>> Then why is it not a lexical reference at top level, where it resolves to 42?
>
> Because there exists no toplevel lexical variables.
That question was badly worded, oops.
>> It looks as if the existence of a lexical scope is shadowing the reference,
>> even though that lexical scope doesn't bind x.
>
> The lexical scope in question cannot shadow any toplevel variable X,
> since there is none defined.
Yes, but in some sense it captures the reference. Simply by being wrapped in
the lambda, X in your example does not resolve to the same thing as an
unwrapped X. The wrapped reference is in a lexical environment which doesn't
define X, but somehow that interferes with X resolving to its global value.
That set of evaluation rules is nonsensical. I don't see where you are coming
from with that, or where it going.