>
> Why do you think we told you to use earmuffs for your special variables?
>
That's true. Should have done that. Maybe I was too much inspired by
Doug Hoyte's book where he argues against the earmuffs, but for situations
like mine they are probably the best solution. Thanks!
>
>> So,
>> - is there a way to "unspecialize" variables?
>
> No. But you can unintern the symbol, and re-read all definitions that
> used the old symbol. This is somewhat violent.
Agreed and a bit unsafe as in general you do not get an error message
that tells you something's wrong, you might just get strange behavior.
>> - What else could be used instead of defparameter/defvar to create top-
>> level bindings?
>
> define-symbol-macro.
Ah, ok, never would have thought of using them in that context. Very nice.
> This allows to define global lexical variables. Google for defglobal or
> deflexical.
SBCl does not have deflexical, but in fact has a defglobal.
I just don't think it's useful for interactive development as it
prevents the redefinition of the function:
; ------------------------
CL-USER> (defun test ()
(let ((l '(1 2 3)))
(lambda ()
(reverse l))))
TEST
CL-USER> (defglobal l (test))
L
CL-USER> (funcall l)
(3 2 1)
CL-USER> (defun test ()
(let ((l '(a b c)))
(lambda ()
(reverse l))))
; in: DEFUN TEST
; (LET ((L '(A B C)))
; (LAMBDA () (REVERSE L)))
;
; caught ERROR:
; L names a global lexical variable, and cannot be used as a local
variable.
;
; compilation unit finished
; caught 1 ERROR condition
STYLE-WARNING: redefining COMMON-LISP-USER::TEST in DEFUN
TEST
CL-USER> (funcall l)
(3 2 1)
CL-USER>
; ------------------------
>> - How do you get around this kind of issues in your daily coding?
>
> We just use the fine earmuff convention!
Plain simple. Really should have though of that, thanks!
Well, but now I have to hope that nobody else uses a variable named *l*
anywhere else in the code I'm including, right? I know, that's what
packages are for, but one never knows.
I'll probably take a look at your define-symbol-macro suggestion.
Best,
Stefan