Rainer Joswig <joswig@lisp.de> wrote:
+---------------
| If you use DEFPARAMETER (and top-level variables) NEVER (!!!)
| use variable names like s, i, x, and so on. DEFPARAMETER
| declares a variable special and that would mean
| that local (!!!) variables with those names will be
| special, too! Convention is to use something like *s*.
+---------------
That's why I (nearly) always use my DEFLEX macro[1] for such
top-level manually-typed variables -- it uses DEFINE-SYMBOL-MACRO
to redirect to a (related) constructed *...* name so that the
top-level variable *can* be lexically re-bound:
> (deflex foo 11)
FOO
> (defparameter *bar* 22)
*BAR*
> (defun top-vars () (list foo *bar*))
TOP-VARS
> (let ((foo 33)
(*bar* 44))
(list* :local foo *bar* :global (top-vars)))
(:LOCAL 33 44 :GLOBAL 11 44)
>
It prevents a lot of accidents while still allowing the
convenience of names like FOO, BAR, X, Y, Z, I, J, K, S, etc.
[Though you still have to avoid names like "T"! ;-} ]
-Rob
[1] See <URL:news:H8Odna8j0qXvt7LbnZ2dnUVZ_viunZ2d@speakeasy.net>
(barely a month ago) for my latest version, along with a
pointer to a required patch to CMUCL-19c or earlier for
symbol-macro handling in MACROEXPAND-1.
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607