Re: Is DEFCONSTANT broken?
- From: Kaz Kylheku <kkylheku@xxxxxxxxx>
- Date: Mon, 22 Jun 2009 07:56:59 +0000 (UTC)
On 2009-06-22, Kaz Kylheku <kkylheku@xxxxxxxxx> wrote:
On 2009-06-22, Ron Garret <rNOSPAMon@xxxxxxxxxxx> wrote:
In article
<2e409792-6696-45b5-9474-636a45da86d2@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Scott Burson <FSet.SLB@xxxxxxxxx> wrote:
On Jun 21, 6:12 pm, Ron Garret <rNOSPA...@xxxxxxxxxxx> wrote:
Actually, DEFVAR comes closest to doing what I want. But I also want to
insure that the value doesn't change or get bound.
Well, there's always DEFINE-SYMBOL-MACRO...
Doesn't work, because it doesn't insure the value won't change:
[ron@mickey:~/Desktop]$ cat test.lisp
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-symbol-macro c7 '#.(gensym))
(defun c7 () c7)
Right; you get a different instance of the c7 macro when compiling and
loading.
It's evaluated again, just like the initializing value of defconstant.
How about this:
;; macro only at compile time
(eval-when (:compile-toplevel)
(define-symbol-macro c7 '#.(gensym)))
;; function only available in compiled form
(eval-when (:load-toplevel)
(defun c7 () c7))
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.
I suppose we could go as far as:
(eval-when (:load-toplevel)
(eval `(define-symbol-macro c7 ',(c7))))
Now c7 macroexpands to the actual symbol, quoted, similarly to the
way it did at compile time.
.
- Follow-Ups:
- Re: Is DEFCONSTANT broken?
- From: Ron Garret
- 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
- Is DEFCONSTANT broken?
- Prev by Date: Re: rip erik naggum
- Next by Date: Re: declaring a function to be special
- Previous by thread: Re: Is DEFCONSTANT broken?
- Next by thread: Re: Is DEFCONSTANT broken?
- Index(es):
Relevant Pages
|