views:

84

answers:

2

I have some lisp initialisation code:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (require 'asdf))

(eval-when (:compile-toplevel :load-toplevel :execute)
  (push #p"c\:\\lisp\\clsql-4.0.4\\" asdf:*central-registry*))

Why does that version compile, while this version:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (require 'asdf)
  (push #p"c\:\\lisp\\clsql-4.0.4\\" asdf:*central-registry*))

produces an error during compile-file in the 3rd line, with asdf an unrecognised package?

I'm using ccl, and (require 'asdf) is documented as bringing in the built-in version of ASDF.

+8  A: 

The following may be inaccurate in some details, but it is approximately like this:

There are four phases that the Lisp "engine" goes through: read time, macro expansion time, compile time, and run time.

Each top-level form is first read in completely. Reading, however, involves resolution of the respective symbols. Since ASDF is not yet loaded during read time of your eval-when form, the symbol asdf:*central-registry* cannot be resolved yet, and this produces the mentioned read error.

Svante
+4  A: 

See the answer by Svante.

Sometimes you might want to work around this. Then you need to look up the symbol in the code at RUNTIME.

(push somepath (symbol-value (find-symbol "*CENTRAL-REGISTRY*" "ASDF")))

Above code can be used, because the symbol asdf:*central-registry* is not used directly but looked up at runtime using the symbol name and the package name.

Rainer Joswig