2 ms·
In Common Lisp, and similar dialects, the module concept is certainly not tied to a file. In fact, there is no module concept. Packages work at the symbol level
by kazinator 7y ago
In Common Lisp, and similar dialects, the module concept is certainly not tied to a file. In fact, there is no module concept. Packages work at the symbol level. Any file can use symbols from any package.
The concept of a compilation unit is closely tied to that of a file. That's not even remotely the same thing as a module.
Even so, Common Lisp has with-compilation-unit which allows multiple files to be compiled together. They still emit separate files, but for the purpose of diagnosis (warnings) they are considered one unit. In concrete terms, complaining about undefined variables and functions is deferred until the entire compilation unit is processed.
Top-level form processing is deliberately contrived in order to make certain practical situations conform to obvious expectations.
For instance, suppose that we have a top-level form:
(progn (defmacro foo ...) (foo))
this cannot work if the entire form is macro-expanded first, and then evaluated, because then (foo) is undefined.
The eval-when control over the top-level is also very important in the face of compilation.