[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can I declare ignore a global?



In article <poeck-1202951825350001@wi6a65.informatik.uni-wuerzburg.de>,
poeck@informatik.uni-wuerzburg.de (Karsten Poeck) wrote:

> Is this a bug in MCL 2.0.1 or is the declaration illegal?
> 
> Karsten
> 
> 
> (defvar dummy-global)
> 
> (defun test (dummy-global)
>   (declare (ignore dummy-global))
>   1)
> 
> #|
> ? 
> ;Compiler warnings :
> ;   Variable DUMMY-GLOBAL not ignored, in TEST.
> TEST
> 
> |#

This apparently strange behavior is caused by the fact that DEFVAR
causes the defvar'ed symbol to be dynamically rather than lexically
bound wherever it appears.  This causes the compiler to insert a
tacit assignment to the global variable, which results in the warning.
For this reason, it is usually considered poor style to use a global
variable name as an argument to a function.

E.

-- 

Erann Gat
gat@robotics.jpl.nasa.gov