[slime-devel] What's the difference between compile and load?
Thomas F. Burdick
tfb at ocf.berkeley.edu
Thu Mar 1 16:42:32 UTC 2007
On 3/1/07, E'Chao Zhang <echaozh at gmail.com> wrote:
> Hi all,
>
> I'm new to the language and to the REPL environment.
>
> When I'm using Slime, and use C-c C-k to compile-and-load a file which
> contains constant definitions, Slime sometimes complains about constant
> redefinition. On the other hand, when I use C-c M-k to just compile the
> file, Slime sometimes just ignores the change in the file. I'm not quite
> sure if the latter phenomenon is just coincidence or it is so designated.
This isn't a Slime issue as much as in implementation one. You don't
say what Lisp you're using, but I assume it's SBCL, as that matches
the behavior you described.
The problem is that compiling a form *may* cause the things it defines
to become defined, and in the case of constants and SBCL, it does.
Then when you load the file, it gets redefined. Which is fine if the
constant was 3, but not if it was '(1 2 3).
A common solution is to do something like:
(defmacro defconstant-equal (var value &optional doc)
`(defconstant ,var
(if (not (boundp ',var))
,value
(let ((old (symbol-value ',var))
(new ,value))
(if (equal old new)
old
(prog1 new
(cerror "Redefine it anyway"
"New value ~S for constant ~S is
not equal to old value ~S"
new ',var old)))))
,@(when doc (list doc))))
Then use defconstant-equal instead of defconstant. Or just use defparameter.
More information about the slime-devel
mailing list