[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Packages: where is the beef ?

> According to my simple minded intuition, packages are name scopes in which I can
> define what ever symbols I want to without having conflicts.
> Unfortunately, is is NOT true in Common Lisp (at least not in Allegro
> Common Lisp).

Still too simple -- besides a package having it's own symbols, it also
inherits symbols from the package(s) it uses.


> First I tried to make my own structure named 'ASSERT' in my own private
> package.

But it wasn't; it was actually in the COMMON-LISP package.
Check the value of (symbol-package 'ASSERT) when in your package.

Here are some of the possible work-arounds:

 1. If you are not going to use ASSERT often, you can shadow it in your
    package, so that MY-PACKAGE::ASSERT will be seen instead.

    If you still want to use COMMON-LISP:ASSERT, you can by qualifying it
    explicitly with a package name (the package name, or one of its nicnames).

 2. You can create a separate package (say, MY-STRUCTS) which does not
    USE-PACKAGE the lisp package, and put your structure definition in it,
    then export the creation and accessor functions.  You don't want to
    export ASSERT from MY-STRUCTS it you plan to use the MY-STRUCTS package.
    If you need to refer to it, you may by explicit qualification:  MY-STRUCTS::ASSERT.

The same thing goes for CLASS.  Since these symbols are in the LISP
package, the various structure/class functions/methods which get
created are created in the symbol-package of the name of the
structure/class.  This is the LISP package, but the LISP package is
locked (for your own protection), thus the error you witnessed.