[Openmcl-devel] User contributions

Ron Garret ron at awun.net
Sun Jun 14 18:21:20 PDT 2009


On Jun 13, 2009, at 6:20 PM, Ron Garret wrote:
>
> But I think this is the Right Answer:
>
> (defmacro defguardian (name)
>   `(defconstant ,name (if (boundp ',name) ,name (gensym))))
>
> Or if you're really being paranoid:
>
> (defmacro defguardian (name)
>   `(defconstant ,name (if (boundp ',name) ,name '#.(gensym))))

Bloody hell, that doesn't work either!

Do this:

(eval-when (:compile-toplevel :load-toplevel :execute)

(defun noisy-gensym () (format t "~&Calling gensym") (gensym))

(defmacro defguardian (name)
   `(defconstant ,name (if (boundp ',name) ,name (noisy-gensym))))

(defguardian foo)

(defun foo () foo)

)

Compile-and-load and observe that noisy-gensym gets called twice (and  
that foo and (foo) have different values).

This is getting ridiculous.  I humbly submit that there's a case to be  
made that allowing this kind of behavior is a bug in the standard.   
Or, failing that, a freedom that it might be wiser to choose to  
forego.  Both CLisp and SBCL do the Right Thing with a simple  
defconstant.  It should not be this hard to make a guardian.  In fact,  
at this point I still don't know a way to do it that actually works in  
a compiled file in CCL.

rg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20090614/8b9d1374/attachment.htm>


More information about the Openmcl-devel mailing list