Re: redefined constant value

Roger Corman <[email protected]> Tue, 28 Oct 2003 18:09:16 -0800
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
This is actually a feature, not a bug. As an optimization, the compiler is putting a constant value into the code if defined with defconstant. If you don't want this, then don't use defconstant (use, for example, defparameter, to get the desired behavior).

The ansi spec is clear that this is undefined behavior in common lisp and therefore portable common lisp code cannot rely on the behavior you get from CLisp (or Corman Lisp).

 From the hyperspec, DEFCONSTANT:


A constant defined by <file://#defconstant>defconstant can be redefined with <file://#defconstant>defconstant. However, the consequences are undefined if an attempt is made to assign a <file://26_glo_v.htm#value>value to the <file://26_glo_s.htm#symbol>symbol using another operator, or to assign it to a <file://26_glo_d.htm#different>different <file://26_glo_v.htm#value>value using a subsequent <file://#defconstant>defconstant. 

The last clause of the statement applies here.

That said, there is supposed to be a way to turn this optimization off, which would make the behavior as you suggest (like CLIsp). The variable ccl::*compiler-fold-constants* is true by default and setting it to false (NIL) should change the behavior. I notice that this doesn't work correctly, so the next kernel update will fix this. This variable does work in other cases (such as to prevent constant expression folding).

Roger

At 05:28 AM 10/26/2003, you wrote:
>Here's the problem:
>
>(defconstant +a+ 22)
>> +A+
>
>(defun foo ()
>    +a+)
>> FOO
>
>(foo)
>> 22
>
>;redefining the constant:
>(defconstant +a+ 33)
>> ;;; Warning: Redefining constant +A+ with previous value 22 and new 
>value 33
>> +A+
>
>(foo)
>> 22
>
>
>;redefining the function
>(defun foo ()
>     +a+)
>> FOO
>
>(foo)
>> 33
>
>
>BTW, CLISP doesn't exhibit this behaviour.
>
>                 Thanks, Denis.
>
>
>
>To unsubscribe from this group, send an email to:
>[email protected]
>
> 
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/SyjtlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/