make-package
make-package Function
Syntax:
make-package package-name &key nicknames use → package
Arguments and Values:
package-name—a string designator .
nicknames—a list of string designators. The default is the empty list.
use—a list of package designators. The default is implementation-defined.
package—a package.
Description:
Creates a new package with the name package-name.
Nicknames are additional names which may be used to refer to the new package.
use specifies zero or more packages the external symbols of which are to be inherited by the new package. See the function use-package.
Examples:
(make-package ’temporary :nicknames ’("TEMP" "temp")) → #<PACKAGE "TEMPORARY"> (make-package "OWNER" :use ’("temp")) → #<PACKAGE "OWNER">
(package-used-by-list ’temp) → (#<PACKAGE "OWNER">)
(package-use-list ’owner) → (#<PACKAGE "TEMPORARY">)
Affected By:
The existence of other packages in the system.
Exceptional Situations:
The consequences are unspecified if packages denoted by use do not exist.
A correctable error is signaled if the package-name or any of the nicknames is already the name or nickname of an existing package.
See Also:
defpackage, use-package
Notes:
In situations where the packages to be used contain symbols which would conflict, it is necessary to first create the package with :use ’(), then to use shadow or shadowing-import to address the conflicts, and then after that to use use-package once the conflicts have been addressed.
When packages are being created as part of the static definition of a program rather than dynamically by the program, it is generally considered more stylistically appropriate to use defpackage rather than make-package.
Expanded Reference: make-package
Basic Usage: Creating a Simple Package
make-package creates and returns a new package with the given name.
(make-package "NETWORK")
==> #<PACKAGE "NETWORK">
(find-package "NETWORK")
==> #<PACKAGE "NETWORK">
Creating a Package with Nicknames
The :nicknames keyword specifies alternative names for the package.
(make-package "TEMPORARY-STORAGE" :nicknames '("TEMP-STORE" "TS"))
==> #<PACKAGE "TEMPORARY-STORAGE">
(find-package "TS")
==> #<PACKAGE "TEMPORARY-STORAGE">
(package-nicknames "TEMPORARY-STORAGE")
=> ("TEMP-STORE" "TS")
Creating a Package with No Inherited Symbols
Use :use '() to create a bare package that inherits nothing from COMMON-LISP.
(make-package "BARE" :use '())
==> #<PACKAGE "BARE">
;; No inherited symbols at all
(find-symbol "CAR" "BARE")
=> NIL
=> NIL
(find-symbol "+" "BARE")
=> NIL
=> NIL
Creating a Package That Uses Another Package
The :use keyword specifies which packages' external symbols should be inherited.
(defpackage "PROVIDER" (:use) (:export "SERVE"))
(make-package "CONSUMER" :use '("COMMON-LISP" "PROVIDER"))
==> #<PACKAGE "CONSUMER">
(find-symbol "SERVE" "CONSUMER")
;; => PROVIDER:SERVE
;; => :INHERITED
(find-symbol "CAR" "CONSUMER")
=> CAR
=> :INHERITED
Symbol Names vs Package Names
Package names are strings. When a symbol is given, its name (a string) is used.
(make-package 'my-demo :use '())
==> #<PACKAGE "MY-DEMO">
(package-name (find-package 'my-demo))
=> "MY-DEMO"