[Openmcl-devel] Docs on defpackage, in-package, use-package, provides and require

Andrew P. Lentvorski, Jr. bsder at mail.allcaps.org
Tue Aug 17 15:42:53 PDT 2004


On Aug 16, 2004, at 8:24 PM, Hamilton Link wrote:

> (in-package :cl-user)
> (unless (find-package "CLOS-UNIT")
>   (defpackage "CLOS-UNIT"
>     (:nicknames :unit)
>     (:export "API-FN1"
>              "API-CLASS-FOO"
>              "ETC.")) ; ... plus maybe some more API, and a 
> package-use list or import lists depending on the functionality that 
> clos-unit depends upon
>   )
>
> (in-package :clos-unit)
> ;; all your code for clos-unit goes here

I seem to be having a problem with defpackage.  The :export does not 
seem to be exporting symbols in the way I would expect.  Now, this is 
almost certainly my faulty understanding, but I seem to require an 
explicit export statement in my code that I don't expect to need.

I created a small file called junk-unit:

(in-package :cl-user)

(unless (find-package "junk-unit")
   (defpackage "junk-unit"
     (:nicknames :junk-unit :ju)
     (:export "barzz")))

(in-package "junk-unit")

(defun barzz ()
   '"This is bar")

;; This line is required to get exports.  Why?
;; (export '(barzz))



Here's what happens when I try to rely on defpackage for the export:


> Welcome to OpenMCL Version (Beta: Darwin) 0.14.2-040506!
> ? (load "junk-unit")
> #P"/Users/andrewl/openmcl/openmcl/compgeom/junk-unit.lisp"
> ? (apropos 'zz)
> |junk-unit|::BARZZ, Def: FUNCTION
> |junk-unit|:|barzz|
>              ZZ
> ? (use-package "junk-unit")
> T
> ? (apropos 'zz)
> |junk-unit|::BARZZ, Def: FUNCTION
>             |barzz|
>              ZZ
> ? ;; What just happened to |barzz|?  Why is it undefined?
> (barzz)
> > Error in process listener(1): Undefined function BARZZ called with 
> arguments () .


Here's what happens when I explicitly export barzz:

> Welcome to OpenMCL Version (Beta: Darwin) 0.14.2-040506!
> ? (load "junk-unit")
> #P"/Users/andrewl/openmcl/openmcl/compgeom/junk-unit.lisp"
> ? (apropos 'zz)
>  |junk-unit|:BARZZ, Def: FUNCTION
> |junk-unit|:|barzz|
>              ZZ
> ? (use-package "junk-unit")
> T
> ? (apropos 'zz)
>  BARZZ, Def: FUNCTION
> |barzz|
>  ZZ
> ? ;; Aha!  It can be used ...
> (barzz)
> "This is bar"

I can do the export by hand at the bottom of the file with symbols, but 
I would like to know what I am doing wrong that requires that I do so.

Thanks,
-a




More information about the Openmcl-devel mailing list