Opened 10 years ago

Closed 10 years ago

#539 closed defect (invalid)

Constant defined by defconstant isn't contant

Reported by: rongarret Owned by: gb
Priority: normal Milestone:
Component: Compiler Version: trunk
Keywords: Cc:

Description (last modified by gb)

I put the following code in a file:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defconstant c1 (gensym))
  (defun foo () c1)
)

I then compile the file, quit CCL, start it up again, and load the compiled version of the file. When I do that, the value returned by calling (foo) is not the same as the value of C1:

Welcome to Clozure Common Lisp Version 1.4-dev-r12255M-trunk (DarwinX8664)! ? (load #P"/Users/ron/Desktop/test.dx64fsl") ;Loading #P"/Users/ron/Desktop/test.dx64fsl"... C1 FOO #P"/Users/ron/Desktop/test.dx64fsl" ? c1 #:G13 ? (foo) #:G19 ?

This appears to be a bug in compile-file. When I trace the gensym, it's called twice when the file is compiled, but only once if the file is loaded as source.

Change History (1)

comment:1 Changed 10 years ago by gb

  • Description modified (diff)
  • Resolution set to invalid
  • Status changed from new to closed

The spec 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. Therefore, users must ensure that the initial-value can be evaluated at compile time (regardless of whether or not references to name appear in the file) and that it always evaluates to the same value."

Note: See TracTickets for help on using tickets.