Re: Is DEFCONSTANT broken?



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))

Now the problem goes away: there is /no/ C7 symbol macro when you load
the object file. And if you load the source file, there is no c7
function.

Just like in C, there are no more #define constants when you're loading .o
files. And you can't run source without compiling it. (That's not real
programming; you're supposed to edit, compile, then run, right?)

So, everything is cool.
.



Relevant Pages

  • Re: Is DEFCONSTANT broken?
    ... ;; macro only at compile time ... And if you load the source file, ... And you can't run source without compiling it. ... Python iterators to indicate end-of-iteration. ...
    (comp.lang.lisp)
  • Trying to get screamer working
    ... ; Byte Compiling Top-Level Form: ... from a nondeterministic context. ... function defined with DEFUN, the body of a call to the FOR-EFFECTS ... macro, the first argument of a call to the ONE-VALUE macro, the body of ...
    (comp.lang.lisp)
  • Re: Dynamically extends a class with java.lang.reflect.Proxy or similar
    ... Stefan Ram wrote: ... I'm interested to generate a new class and load this class as you say. ... The JSP pages are translated in a Java source file that define a class that extends HTTPServlet and compiled and loaded at runtime. ... There is another way instead creating a source file and compiling it? ...
    (comp.lang.java.programmer)
  • Re: Behaviors between Macros 2 Times
    ... > (defmacro test (x y z) ... > `(format t "this line is in vain because it is not retured by macro ... > this is compiling time ... > It means that the "macro machine" thinkns that the variables were ...
    (comp.lang.lisp)
  • Re: Protected cells
    ... I don't understand about the not compiling if you recorded in xl2003. ... Dim myAllowEditRange As AllowEditRange ... In the macro I'm currently using is there a way ... what I meant is that I want to remove the users ability to edit the ...
    (microsoft.public.excel.misc)