Re: Is DEFCONSTANT broken?



In article <20090704083602.686@xxxxxxxxx>,
Kaz Kylheku <kkylheku@xxxxxxxxx> wrote:


But seriously, how does this fare on Clozure?

;; constant definition for compile time (and source loading)

(eval-when (:compile-toplevel :execute)
(define-symbol-macro c7 '#.(gensym)))

;; function to return value of constant:
;; - if this is compiled, c7 is folded by macroexpansion
;; to return the gensym set up by the above definition,
;; and that gensym is externalized into the compiled file.
;; See CLHS 3.2.4.2.2: uninterned symbols are externalizeable,
;; with a similarity based on their names!!!
;; - if a compiled form of this is being loaded, then the loader will
;; manufacture a gensym similar to the one that existed
;; at compile time; i.e. it will create a symbol
;; with the same name as if by MAKE-SYMBOL.
;; - if this is evaluated as source, then everything
;; is cool; the function refers to c7, which is set
;; up as a macro constant thanks to :execute above.

(defun c7 () c7)

;; load-time constant: now that the compiled file
;; is loaded, we make c7 a synonym for the function
;; call (c7). Thus (eq c7 (c7)) is assured.

(eval-when (:load-toplevel)
(define-symbol-macro c7 (c7)))

See: two different definitions for diferent situations, creating the
illusion of one consistent constant.

That works insofar as (eq c7 (c7)) returns T. However, it's not really
what I want. The main reason I want to use DEFCONSTANT is to prevent c7
from being reassigned or rebound. If C7 is a symbol macro I don't get
that guarantee. If I were willing to rely on the user not to assign or
bind c7 I could just use DEFVAR and be done with it.

rg
.