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

Re: Finding out if a variable is proclaimed special



On Mon Aug 16 at 20:04:25 Thomas A. Russ writes:
> I am wondering how (in MCL, not necessarily portably) to determine if
> a variable is proclaimed special.

The function proclaimed-special-p will determine whether the variable
is special:
  ? ? (defparameter *c* 1)
  *C*
  ? (proclaimed-special-p '*c*)
  T
  ? (proclaimed-special-p 'an-undeclared-variable)
  NIL

In the example, replacing defparameter by defvar has the same effect.

Note: It is standard practice to denote special variables by beginning
and ending them with an asterisk. This way the "special" variables  standout.
For example, all of the 35 defvar variables in library/loop.lisp follow
this convention


And Thomas A. Russ also writes: 
> We would like to spare our users these messages.
 
> (defvar c 3)
> (compile nil
>         '(lambda (a b c)
>            (declare (ignore b c))
>              (* a a)))
> ;Compiler warnings:
> ;   Variable C not ignored, in an anonymous lambda form.

> I would like to be able to detect when a variable is proclaimed
> special and thus avoid this compiler warning.

To eliminate the warnings without checking for
special variables, then declare the variables to be ignorable:

(defvar c 3)
(compile nil
         '(lambda (a b c)
            (declare (ignorable b c))
            (* a a)))

mark