ECL allows giving packages local nicknames: they allow short and easy-to-use names to be used without fear of name conflict associated with normal nicknames.
A local nickname is valid only when inside the package for which it has been specified. Different packages can use same local nickname for different global names, or different local nickname for same global name.
The keyword :package-local-nicknames
in *features*
indicates the support for this feature.
Options are extended to include
:local-nicknames (local-nickname actual-package-name)*
The package has the specified local nicknames for the corresponding actual packages.
Example:
(defpackage :bar (:intern "X")) (defpackage :foo (:intern "X")) (defpackage :quux (:use :cl) (:local-nicknames (:bar :foo) (:foo :bar))) (find-symbol "X" :foo) ; => FOO::X (find-symbol "X" :bar) ; => BAR::X (let ((*package* (find-package :quux))) (find-symbol "X" :foo)) ; => BAR::X (let ((*package* (find-package :quux))) (find-symbol "X" :bar)) ; => FOO::X
cl_object
si_package_local_nicknames (cl_object package_designator)
¶Returns an alist of (local-nickname . actual-package)
describing the nicknames local to the designated package.
When in the designated package, calls to find-package
with any
of the local-nicknames will return the corresponding actual-package
instead. This also affects all implied calls to find-package
,
including those performed by the reader.
When printing a package prefix for a symbol with a package local nickname, the local nickname is used instead of the real name in order to preserve print-read consistency.
cl_object
si_package_locally_nicknamed_by_list (cl_object package_designator)
¶Returns a list of packages which have a local nickname for the designated package.
cl_object
si_add_package_local_nickname (cl_object local_nickname, cl_object actual_package, cl_object package_designator)
¶Adds local-nickname for actual-package in the designated package, defaulting to current package. local-nickname must be a string designator, and actual-package must be a package designator.
Returns the designated package.
Signals a continuable error if local-nickname is already a package local nickname for a different package.
When in the designated package, calls to find-package
with the
local-nickname will return the package the designated
actual-package instead. This also affects all implied calls to
find-package
, including those performed by the reader.
When printing a package prefix for a symbol with a package local nickname, the local nickname is used instead of the real name in order to preserve print-read consistency.
cl_object
si_remove_package_local_nickname (cl_object old_nickname, cl_object package_designator)
¶If the designated package had old-nickname as a local nickname
for another package, it is removed. Returns true if the nickname
existed and was removed, and nil
otherwise.