Difference between `uiop/package:define-package` and `defpackage`?

817 views Asked by At

In Common Lisp with ASDF what is the difference between the define-package in uiop/package and the defpackage macro?

1

There are 1 answers

1
Ehvince On BEST ANSWER

UIOP's one has more clauses.

https://common-lisp.net/project/asdf/uiop.html#UIOP_002fPACKAGE

define-package supports the following keywords: use, shadow, shadowing-import-from, import-from, export, intern -- as per cl:defpackage.

those are the same ones. But the rest of the docstring introduces more of them: recycle, mix, reexport

I have used reexport which makes the following easier: you don't want to fully use package A (for example, Alexandria). You want to import a couple symbols (easy, with import-from), and you also want to export them (easy too, with export). But in doing so, you had to write the symbols twice. reexport saves duplication.

I heard some complains that defpackage would fail to reload a package in some situations, and define-package worked fine, but I didn't encounter this situation.

(edit): another difference: let's say you ":use" a package in your defpackage definition. Now you erase that line and you compile the package definition again. Your Lisp gives you a warning, telling that your package "also uses the following packages" and lists the one you removed from the definition. You removed the line, but the package still "uses" what you wanted to remove. You can check with (describe (find-package :my-package)).

Do the same with UIOP's define-package: you don't have warnings and your package doesn't "use" the one you removed from the definition anymore, as expected.