From: Paolo Amoroso
Subject: Package definitions for reusable libraries: where should they go?
Date: 
Message-ID: <37c4fd2e.293787@news.mclink.it>
Concerning the use of DEFPACKAGE, the HyperSpec says (among the notes in
the DEFPACKAGE entry):

   It is recommended that the entire package definition is put in a
   single place, and that all the package definitions of a program are in
   a single file. This file can be loaded before loading or compiling
   anything else that depends on those packages. Such a file can be read
   in the COMMON-LISP-USER package, avoiding any initial state issues.

What about a small reusable library contained in a single file? Its package
definition can be separated from the rest of the code as recommended. So it
is necessary to create a file with appropriate package definitions,
including the one for the given library, each time the library is needed by
an application. Is this the way to go for small reusable libraries?

An alternative is to put a DEFPACKAGE form in the same file containing the
rest of the library. This doesn't require to create a new package
definition each time the library is used. What are the potential drawbacks
of this approach?


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/

From: Kent M Pitman
Subject: Re: Package definitions for reusable libraries: where should they go?
Date: 
Message-ID: <sfwbtburfhr.fsf@world.std.com>
·······@mclink.it (Paolo Amoroso) writes:

> Concerning the use of DEFPACKAGE, the HyperSpec says (among the notes in
> the DEFPACKAGE entry):
> 
>    It is recommended that the entire package definition is put in a
>    single place, and that all the package definitions of a program are in
>    a single file. This file can be loaded before loading or compiling
>    anything else that depends on those packages. Such a file can be read
>    in the COMMON-LISP-USER package, avoiding any initial state issues.
> 
> What about a small reusable library contained in a single file? Its package
> definition can be separated from the rest of the code as recommended. So it
> is necessary to create a file with appropriate package definitions,
> including the one for the given library, each time the library is needed by
> an application. Is this the way to go for small reusable libraries?

For single-file applications, I sometimes precede the IN-PACKAGE with a
DEFPACKAGE, but this thwarts some text editors, which look for the IN-PACKAGE
and give up before they find it.

Further, Symbolics Genera looks at the "file attribute list" instead of an
IN-PACKAGE and while it is general enough to contain export info, etc., it's
rare that anyone puts it.

The problem occurs if the package needs to be demand-created because
it doesn't exist.  If you make it wrong, you can make a mess.  It's
better to have it loadable separately so that you can load it to edit
the file even when you don't want to load the application part of the
file.
 
As a rule, we folks who are used to Genera generally always make two standard
files with every system:
 sysdcl.lisp  - contains the system definition (usually a defsystem)
 pkgdcl.lisp  - contains the package setup
And then there are other files.   But it's just part of the ritual of system
creation to make these two.

> An alternative is to put a DEFPACKAGE form in the same file containing the
> rest of the library. This doesn't require to create a new package
> definition each time the library is used. What are the potential drawbacks
> of this approach?

I didn't understand the part about making a new definition each time it's
used.  Isn't it only loaded once?  Whether you use defsystem or 
require/provide, it shouldn't get loaded additional times.  And even if it
is, DEFPACKAGE isn't "making" new definitions, it's just "assuring" at least
one compatible definition.

Or maybe I'm missing something...
From: Paolo Amoroso
Subject: Re: Package definitions for reusable libraries: where should they go?
Date: 
Message-ID: <37c6dec0.46561@news.mclink.it>
On Thu, 26 Aug 1999 10:41:20 GMT, Kent M Pitman <······@world.std.com>
wrote:

> ·······@mclink.it (Paolo Amoroso) writes:
> > An alternative is to put a DEFPACKAGE form in the same file containing the
> > rest of the library. This doesn't require to create a new package
> > definition each time the library is used. What are the potential drawbacks
> > of this approach?
> 
> I didn't understand the part about making a new definition each time it's
> used.  Isn't it only loaded once?  Whether you use defsystem or 

The implications of my second sentence ("This doesn't require...")
contradict the perceived benefits asserted by the first ("An alternative
is..."). Sorry for the mess :-(

The second sentence means that putting DEFPACKAGE in the same file
containing the rest of the code doesn't require to add--i.e. edit,
write--it to a separate file such as pkgdcl.lisp you mentioned. The
sentence further seems to imply that the package definition may need to be
customized to integrate the library with a larger system. If so, this
solution is better than the single file approach because changes are
localized to the package definition file, and the rest of the code is not
affected. 


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/