Subject: Re: Is there a better way?
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 22 Sep 2007 07:14:55 -0500
Newsgroups: comp.lang.lisp
Message-ID: <nqednViuEqeimmjbnZ2dnUVZ_s-pnZ2d@speakeasy.net>
Raffael Cavallaro  <raffaelcavallaro@pas-d'espam-s'il-vous-plait-mac.com> wrote:
+---------------
| Kent M Pitman <pitman@nhplace.com> said:
| > Does this help?
| 
| Maybe I'm confused as well, but for me the issue arises because I
| would expect that (constantp x) would tell me if x is a constant
| *object*, which is to say, I would expect that constantp would tell
| me if an object is immutable. Instead, constantp tells me if a
| *form* is a constant form, which is not always helpful.
+---------------

That's correct [in both senses]. E.g., in an implementation like CMUCL
which chooses[1] to evaluate the value of a (DEFCONSTANT <var> <form>)
at LOAD time, a (CONSTANTP <var>) can return T at compile time and yet
the *value* of <var> is *NOT* available at compile time!!

To say that at times this can be frustrating is an understatement...  ;-}


-Rob

[1] Legally, according to CLHS "Macro DEFCONSTANT":

        If a defconstant form appears as a top level form, the
        compiler must recognize that name names a constant variable.

    That implies that a (CONSTANTP <var>) later in the code *must*
    return T, but:

	An implementation may choose to evaluate the value-form
	at compile time, load time, or both.

    So attempting to *reference* the value of <var> at compile time
    is allowed to fail... even if <form> is a simple literal!

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607