[Openmcl-devel] User contributions
Ron Garret
ron at awun.net
Sat Jun 13 18:03:15 PDT 2009
On Jun 13, 2009, at 5:58 PM, Ron Garret wrote:
>
> On Jun 13, 2009, at 4:43 PM, Brian Mastenbrook wrote:
>
>> On Jun 13, 2009, at 5:51 PM, Ron Garret wrote:
>>
>>> And just in case anyone actually tried this, it won't work. The
>>> reason is that I'm doing (essentially) this:
>>>
>>> (defconstant +guardian+ (gensym))
>>>
>>> as part of my iterators code. But it turns out this is a broken
>>> idiom
>>> because, as Gary points out in http://trac.clozure.com/ccl/ticket/
>>> 539:
>>>
>>> The spec says:
>>>
>>> "If a defconstant form appears as a top level form, the compiler
>>> must
>>> recognize that name names a constant variable. An implementation may
>>> choose to evaluate the value-form at compile time, load time, or
>>> both.
>>> Therefore, users must ensure that the initial-value can be evaluated
>>> at compile time (regardless of whether or not references to name
>>> appear in the file) and that it always evaluates to the same value."
>>>
>>>
>>> I am open to suggestions on how to fix this because this leave me
>>> at a
>>> bit of a loss.
>>
>> Use a symbol-macro instead:
>>
>> (macrolet ((define-guardian (name) `(define-symbol-macro ,name ',
>> (gensym))))
>> (define-guardian +guardian+))
>
> That fails if you reload an uncompiled version of the file.
>
> Ironically, using DEFVAR instead of DEFCONSTANT or DEFINE-SYMBOL-MACRO
> comes closest to doing the Right Thing -- but then you can't rely on
> the system to prohibit assignment and rebinding.
>
This seems to mostly work:
(defconstant +guardian+ '#.(gensym))
rg
More information about the Openmcl-devel
mailing list