[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Compilation and package system
There are a number of ways to let the compiler know about the package that a
file will be loaded into. The portable, Common Lisp way to do this is with a
call to In-Package at the beginning of a file, as suggested in CLTL, on page
189. The Lisp Machine -*- file comment hack (which is used by the editor,
compiler, and loader) has a few drawbacks.
First of all, it is not portable. People write Common Lisp programs with a -*-
package specification, but these programs must be modified (by adding a real
In-Package to the program text) when they are moved to non-Lisp Machine Common
Secondly, one cannot put all of the information about the packages Use'd or
symbols Import'ed in the file comment. One cannot accurately fix up the
package environment by looking at the file comment. I suppose one could hair
it up to include imports and shadows and whatnot (maybe someone already has),
but that just leaves one with more stuff to "translate into Common Lisp" when
he moves his program off of the Lisp Machine.
Finally, the Symbolics Common Lisp Compatibility Package will give an error
when one attempts to load or compile a file with a header something like that
presented below, because it interprets the file comment, and wants to find any
package specified there before reading anything in the file. In fact, the
first form read may be the one that creates the package, so it may not be there
for the file comment gremlin to interpret. In-Package is a nice language
feature that Does The Right Thing, but has been rendered useless on the Lisp
Machine by zealous use of file comment magic.
We have adopted the convention that any -*- package specification is for the
editor only, and that the compiler and friends should get stuff out of Lisp
forms. Thus, a typical Spice Lisp system file might begin with something like:
;;; -*- Package: Lisp; Log: Code.Log -*-
;;; ...blah blah blah...
(in-package "LISP" :use '("SYSTEM"))
(export '(things that this file defines))
The editor knows which package to associate with a buffer created when visiting
this file, but the compiler and loader and everyone else just read Lisp forms,
the way Father Lisp wanted them to.
Since the -*- convention is not part of Common Lisp (and perhaps for good
reason), I would encourage EVERYONE writing Common Lisp programs to begin each
file in the way suggested in CLTL. Smart editors need to know things like the
package (so that functions compiled in the text editor end up in the right
package, for example), however, so it might be worth some effort to standardize
the semantics of -*- file comments. Unfortunately, I imagine neither the Lisp
Machine community nor the Spice Lisp community is willing to give in.