Subject: Re: Need some combination of case and cond
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 19 May 2004 08:00:28 -0500
Newsgroups: comp.lang.lisp
Message-ID: <EtmdnQsRh-rxxzbdRVn-gQ@speakeasy.net>
Steven M. Haflich <smh_no_spiced_ham@alum.mit.edu> wrote:
+---------------
| Harald Hanche-Olsen wrote:
| > | What happens when the file is compiled?  Is there a need to wrap
| > | eval-when forms around the defconstant forms?
| > 
| > Um, after some further reading of the DEFCONSTANT section in the CLHS
| > I guess not.  Sorry 'bout the noise.
| 
| I'm glad that, after all this noise about naming of gensyms etc., someone
| has resturned to the initial queation.  But I don't agree with the above
| conclusion.
...
| ...the ANS says:
| 
|   If a defconstant form appears as a top level form, the compiler must
|   recognize that name names a constant variable. An implementation may
|   choose to evaluate the value-form at compile time, load time, or both.
| 
| If the implementation chooses _not_ to evaluate the value form, that
| value form can hardly be available to the reader.  Even if the
| implementation +does+ choose to evaluate the value form at compile
| time, I can still find no proof within the ANS that the _reader_ will
| have that definition available to it.
+---------------

And in fact, in CMUCL it will *NOT*!!

This led to an actual portability problem in Tim Bradshaw's HTOUT macro 
package a while back, which he & I hashed out at great length before
reaching the same conclusion you reach above. [ISTR he was using Lispworks,
while I was using CMUCL.] CMUCL obeys the letter of the ANS, but both
Tim & I agreed that the above-quoted section of the ANS makes CONSTANTP[1]
practically *useless* [or at least non-portable] at compile time for
doing any kind of constant folding, since it is possible in a conforming
implementation that CONSTANTP [at compile time, say, in a macro] might
return "T" for every sub-form of a "constant" expression, yet the value(s)
of some sub-form(s) might not be available at compile time. (*sigh*)


-Rob

[1] The CLHS says:

	...symbols declared as constant by the user in the indicated
	environment using DEFCONSTANT are always considered constant forms
	and must be recognized as such by CONSTANTP.

    But what is *NOT* required by DEFCONSTANT is that the *value* of a
    "symbol declared as constant by the user" be available at compile time!

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