From: Christophe Degude
Subject: Special variable and his definition
Date: 
Message-ID: <3CCE7F25.8E3EEAA1@emi.u-bordeaux.fr>
Hi,

I declare (in a function) a variable, named Tree by this instruction:
(declare (special Tree))
In the function, i call a macro which use my variable Tree.

I have this: Warning: This variable is undefined: TREE, but the
execution runs good.

How can I "hide" this warning, or is an another method exists to
implement that?

Thanks in advance,
    Bloodbowlman

From: Kent M Pitman
Subject: Re: Special variable and his definition
Date: 
Message-ID: <sfwvga19xa3.fsf@shell01.TheWorld.com>
Christophe Degude <······@emi.u-bordeaux.fr> writes:

> Hi,
> 
> I declare (in a function) a variable, named Tree by this instruction:
> (declare (special Tree))
> In the function, i call a macro which use my variable Tree.
> 
> I have this: Warning: This variable is undefined: TREE, but the
> execution runs good.
> 
> How can I "hide" this warning, or is an another method exists to
> implement that?
> 
> Thanks in advance,
>     Bloodbowlman

If you show us the program, answering this question will be easier.

By the way, as an important rule of style, you should only declare
special a variable that has *'s on both ends of its name.  Call your
variable *TREE* instead of TREE.  By doing this, you will be assured
that human readers know of your intent that the variable be special
whether or not they have seen the declaration.  In addition, doing
this assures that you do not accidentally perturb some reference to a
variable named TREE that you had intended to be lexical.

It is _possible_ to have a special variable called TREE.  It is just
not a good idea.

(Note that Lisp does case translation at READ-time, so what you write
as tree, Tree, or TREE in your program are all the variable TREE.)
From: Kaz Kylheku
Subject: Re: Special variable and his definition
Date: 
Message-ID: <7hyB8.11520$a04.51983@tor-nn1.netcom.ca>
On Tue, 30 Apr 2002 13:25:25 +0200, Christophe Degude
<······@emi.u-bordeaux.fr> wrote:
>Hi,
>
>I declare (in a function) a variable, named Tree by this instruction:
>(declare (special Tree))
>In the function, i call a macro which use my variable Tree.
>
>I have this: Warning: This variable is undefined: TREE, but the
>execution runs good.

Did you bind the symbol?

  (let (*tree*)
    (declare (special *tree*)) 
    ...)

Another way is to define the special variable in a top level form:

  (defvar *tree*) ;; implicitly made special

If you don't define the variable at the top level or in a block, then
it is undefined: the symbol has no binding. 

Special variables should really be named like this: *tree*.
The problem is that when you declare a symbol to be a special variable, then
all bindings of that symbol have the semantics of dynamic binding. 
The symbol ``tree'' could be used as a lexical variable in some code
that you call, with disastrous consequences if you inadvertantly change
its status to special. E.g.

  (defvar tree 42) ;; now special

  (defvar f (let ((tree 3)) ;; tree is dynamically bound here, not lexically!
              #'(lambda () tree))) ;; closure does not capture tree binding!

  (funcall f)
  ==> 42  ;; what, not 3? 
          ;; Nope, tree reference in closure is dynamic, not lexical.