Subject: Re: setq givs a warning i SBCL, Not CLISP
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 05 Jun 2007 06:57:26 -0500
Newsgroups: comp.lang.lisp
Message-ID: <lPSdnQXq19Y70vjbnZ2dnUVZ_oernZ2d@speakeasy.net>
Richard M Kreuter  <kreuter@progn.net> wrote:
+---------------
| Pillsy <pillsbury@gmail.com> writes:
| > (defmacro deflex (var val)
| >   (let ((backing (gensym)))
| >     `(progn
| >        (setf (symbol-value ',backing) val)
| >        (define-symbol-macro ,var (symbol-value ',backing))))
| 
| This is different from the previous two proposals: repeated evaluation
| of such a deflex creates a fresh value cell, with the result that what
| looks like the same variable in different places can be associated
| with different value cells.
+---------------

Yes, that's one of the reasons that my version of DEFLEX [posted
a couple of weeks ago] creates the backing vauable deterministicly
from the name of the first DEFLEX arg, so you always get the same
value cell each time.

Another reason is that if you happen to MACROEXPAND some code
that references a DEFLEX'd variable, you're not left *totally*
clueless about where the code came from, e.g.:

    > (deflex abc 5)
    
    ABC
    > (macroexpand 'abc)

    *STORAGE-FOR-DEFLEX-VAR-ABC*
    T
    > 

And it plays well with DESCRIBE, too:

    > (describe 'abc)

    ABC is an internal symbol in the COMMON-LISP-USER package.
    It is a symbol macro with expansion: *STORAGE-FOR-DEFLEX-VAR-ABC*.
    > 

+---------------
| > (deflex abc 5)
| ABC
| > abc
| 5
| > (defun some-fun () abc)
| SOME-FUN
| > (some-fun)
| 5
| > (deflex abc 10)
| ABC
| > abc
| 10
| > (defun more-fun () abc)
| MORE-FUN
| > (more-fun)
| 10
| > (some-fun)
| 5
+---------------

Whereas with my version the final (SOME-FUN) also returns 10.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607