Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

make-package without :use

22 views
Skip to first unread message

Phil Roc

unread,
May 17, 2022, 1:37:09 AM5/17/22
to
Good morning,
If I run the following code, I get error messaging stating that
that defun, format, ... are not declared in package BOB, ...

----------
(make-package :bob)
;;:use '("CL"))
(make-package :jane)
;;:use '("CL"))

(in-package "BOB")
(defun foo () (format t "In ~A's, running foo...~%" *package*))
(foo)
(in-package "JANE")
(defun foo () (format t "In ~A's, running foo...~%" *package*))
(foo)
-----------

This version of the code doesn't work either:

----------
(make-package :bob)
;;:use '("CL"))
(make-package :jane)
;;:use '("CL"))

(in-package "BOB")
(defun foo () (format t "In ~A's, running foo...~%" *package*))
(foo)
(in-package "JANE")
(defun foo () (format t "In ~A's, running foo...~%" *package*))
(foo)
-------------

Are there any other solutions besides uncommenting (:use '("CL")')?

Helmut Eller

unread,
May 17, 2022, 4:12:55 AM5/17/22
to
> Are there any other solutions besides uncommenting (:use '("CL")')?

You could write CL:DEFUN instead of DEFUN. If you are in package BOB
and the Lisp system reads DEFUN, then it creates a fresh symbol in the
BOB package, i.e., BOB::DEFUN which is different from CL:DEFUN.

With the :USE CL argument the system first searches in the CL package
for names before deciding to create fresh symbols.

Helmut

Kaz Kylheku

unread,
May 17, 2022, 4:13:43 AM5/17/22
to
On 2022-05-17, Phil Roc <phi...@free.fr> wrote:
> Are there any other solutions besides uncommenting (:use '("CL")')?

The "use" mechanism creates a window from one package to another;
symbols which are exported by the used package are visible in the
using package. They are not actually present in the using package;
it's only a visibility trick.

The only alternative to visibility via use is to actually make
the desired symbols present in your package by importing them
individually. See the functions import and shadowing-import.

--
n
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Zyni Moë

unread,
May 17, 2022, 4:50:14 AM5/17/22
to
Phil Roc <phi...@free.fr> wrote:
> Good morning,
> If I run the following code, I get error messaging stating that
> that defun, format, ... are not declared in package BOB, ...
> [...]
>
> Are there any other solutions besides uncommenting (:use '("CL")')?
>

To be precise you may or may not get such errors since the default for :use
is implementation-defined: your code might 'work' on some implementations
but not on others.

You could make it 'work' on more by:

(make-package :foo)
(use-package '(:cl) ':foo)

This still leaves the package use list only partly specified (it may
include other packages than the CL package). If you want it
fully-specified you must specify it.

However none of this will make your code actually work: make-package &
use-package are functions so the packages you are making will not exist at
compile time so your code cannot be compiled. That is why you should use
defpackage.

--
the small snake
0 new messages