Re: compile-file

Gary Byers <[email protected]> Mon, 25 Apr 2005 15:44:53 -0600 (MDT)
Newsgroups gmane.lisp.openmcl.bugs
Message-ID <[email protected]>

On Mon, 25 Apr 2005, bryan o'connor wrote:

> [this is a simplified test-case for lossage when trying
> to build a merged clx-cvs + openmcl-clx.]
>
> given a file named lose.lisp containing:
>
>  (defconstant +get-string+       129)
>
>  (defun foo () #.+get-string+)
>
> ? (compile-file "lose.lisp")
> Read error between positions 36 and 66 in /Users/bryan/lose.lisp.
>> Error in process listener(1): Unbound variable: +GET-STRING+
>> While executing: "Unknown"
>> Type :GO to continue, :POP to abort.
>> If continued: Retry getting the value of +GET-STRING+.
> Type :? for other options.
>
>
> that should work, right?
>
>  ...bryan
>

Not portably.  The code assumes that COMPILE-FILE has done some sort
of global assignment to +GET-STRING+ when processing the DEFCONSTANT
form, and that EVAL (called via #.) will see the results of this
assignment.

If you commented out the definition of FOO and did:

? (progn
     (makunbound '+get-string+)
     (compile-file "lose.lisp"))

would

? (boundp '+get-string+)

be true or not ?

If the file contained a macro definition (instead of or as well as
a constant definition), would that macro be globally defined as
a result of compiling the file ?

I think that it's legal for the answer to either of these questions
to be either "yes" or "no".  I think that it's also generally more
useful to limit the pervasive effects of defining forms; one can
always ask for the pervasive effect by doing something like:

(eval-when (:compile-toplevel ...)
   (defconstant ...))

but there isn't any way of asking for the more limited effect.  That
"limited effect" is certainly desirable if the definition in a file
being compiled is incompatible with the runtime version:

;;; system-version.lisp
(defconstant system-version 3.14159)
;;; lots of code which references SYSTEM-VERSION elided.

Should compiling that file in version 3.14158 of some system change
the "global" system version (possibly breaking the running system), or
should the constant definition only affect the elided code in that
file (and the global effects only take place when the file is loaded ?)