Re: Is DEFCONSTANT broken?
- From: Ron Garret <rNOSPAMon@xxxxxxxxxxx>
- Date: Mon, 22 Jun 2009 18:46:16 -0700
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
.
- Follow-Ups:
- Re: Is DEFCONSTANT broken?
- From: Kaz Kylheku
- Re: Is DEFCONSTANT broken?
- From: Scott Burson
- Re: Is DEFCONSTANT broken?
- From: Madhu
- Re: Is DEFCONSTANT broken?
- References:
- Is DEFCONSTANT broken?
- From: Ron Garret
- Re: Is DEFCONSTANT broken?
- From: Pascal J. Bourguignon
- Re: Is DEFCONSTANT broken?
- From: Ron Garret
- Re: Is DEFCONSTANT broken?
- From: Pascal J. Bourguignon
- Re: Is DEFCONSTANT broken?
- From: Ron Garret
- Re: Is DEFCONSTANT broken?
- From: Scott Burson
- Re: Is DEFCONSTANT broken?
- From: Ron Garret
- Re: Is DEFCONSTANT broken?
- From: Kaz Kylheku
- Re: Is DEFCONSTANT broken?
- From: Kaz Kylheku
- Is DEFCONSTANT broken?
- Prev by Date: Re: Is DEFCONSTANT broken?
- Next by Date: Re: Is DEFCONSTANT broken?
- Previous by thread: Re: Is DEFCONSTANT broken?
- Next by thread: Re: Is DEFCONSTANT broken?
- Index(es):