Kaz Kylheku
5/15/2015 11:09:00 PM
On 2015-05-15, Barry Margolin <barmar@alum.mit.edu> wrote:
> In article <20150515121906.638@kylheku.com>,
> Kaz Kylheku <kaz@kylheku.com> wrote:
>
>> ANSI CL says, of FMAKUNBOUND:
>>
>> "Removes the function or macro definition, if any, of name in the global
>> environment."
>>
>> But for MAKUNBOUND:
>>
>> "Makes the symbol be unbound, regardless of whether it was previously
>> bound."
>>
>> Well, does that mean variables, or symbol macros too? Moreover, what about
>> the
>> special variable status of the symbol?
>>
>> Are global symbol macros "bindings"? Under DEFINE-SYMBOL-MACRO, there is
>> a blurb of text which suggests they are:
>>
>> A binding for a symbol macro can be shadowed by let or symbol-macrolet.
>>
>> If there is such a thing a "binding for a symbol macro", then MAKUNBOUND
>> had better delete it.
>>
>> CLISP: making it unbound doesn't affect special status:
>>
>> [1]> (defvar x)
>> X
>> [2]> (special-variable-p 'x) ;; CLISP extension in package EXT
>> T
>> [3]> (makunbound 'x)
>> X
>> [4]> (special-variable-p 'x)
>> T
>> [5]> (boundp 'x)
>> NIL
>>
>> Is that conforming? It seems logically inconsistent because (boundp 'x) ->
>> nil
>> is telling us that X is not a variable! Yet special-variable-p insists
>> that X is a variable. I say that if it's unbound, it has no such status.
>
> Of course it does. Specialness is associated with the symbol, not the
> binding. The variable was unbound when you declared it with DEFVAR,
> since you didn't provide an initial value, and MAKUNBOUND doesn't change
> that.
>
>>
>> CLISP: symbol macros are not bindings, and MAKUNBOUND doesn't wipe them:
>>
>> [1]> (define-symbol-macro x '(i am x))
>> X
>> [2]> x
>> (I AM X)
>> [3]> (boundp 'x)
>> NIL
>> [4]> (makunbound 'x)
>> X
>> [5]> x
>> (I AM X)
>> [6]>
>
> One thing to note: the symbol macro has no effect on (symbol-value 'x).
> It's only effective when it's used as a variable in an expression, not
> when operating on the symbol as first-class data.
>
> There probably SHOULD be a way to undo DEFINE-SYMBOL-MACRO, I think it's
> just an omission in the spec.
>
>>
>> CLISP: constants are bindings, but cannot be unbound by MAKUNBOUND:
>>
>> [1]> (defconstant x 42)
>> X
>> [2]> (boundp 'x)
>> T
>> [3]> (makunbound 'x)
>>
>> *** - MAKUNBOUND: X is a constant, may not be used as a variable
>> The following restarts are available:
>>
>> What? I didn't *use* anything; I merely requested its nonexistence!!!
>
> No, you told it to set its value slot to the special "unbound" value.
I'm tripped up by the stupid terminology again that a binding is
an association between a symbol and a value (rather than an abstract
storage location).
Thus DEVAR "establishes a dynamic variable", but doesn't give it a binding
(and it may have one already).
MAKUNBOUND doesn't "disestablish" a dynamic variable; it just robs
it of a value.
We can store value into a dynamic variable which doesn't have a binding.
The binding is then created (to that value).
Okay, now here is a problem.
The description of the SETQ form says this:
"Assigns values to variables."
"(setq var1 form1 var2 form2 ...) is the simple variable assignment
statement of Lisp."
What does it mean to assign? It's not explained under SETQ; but there is a
Glossary entry for the term:
assign v.t. (a variable) to change the value of the variable in a binding
that has already been established. See the special operator setq.
Oops, problem!
;; establish never-been-seen-before as a dynamic variable,
;; without establishing a binding:
(defvar never-been-seen-before)
;; Assignment means to change the value in
;; a binding that has been established,
;; so the following isn't correct: there is no binding.
(setq never-been-seen-before 42)
It seems that part of the ANSI CL document is written from the point of
view of "binding refers to an abstract storage location that is entered into
some environment under a symbol", even though other parts insist that
a binding is an association to a value.
What is a dynamic variable?
dynamic variable n. a variable the binding for which is in the dynamic
environment. See special.
So if something has no binding, it cannot be a dynamic variable, oops!
Yet MAKUNBOUND supposedly preserves a variable as such, yet only
takes away its binding.