Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why must 'require' be evaluated in a separate expression to use of the package

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.

like image 232
John McAleely Avatar asked Jul 06 '09 22:07

John McAleely


1 Answers

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.

like image 107
Svante Avatar answered Oct 26 '22 09:10

Svante