unexport
unexport Function
Syntax:
unexport symbols &optional package → t
Arguments and Values:
symbols—a designator for a list of symbols.
package—a package designator . The default is the current package.
Description:
unexport reverts external symbols in package to internal status; it undoes the effect of export.
unexport works only on symbols present in package, switching them back to internal status. If unexport is given a symbol that is already accessible as an internal symbol in package, it does nothing.
Examples:
(in-package "COMMON-LISP-USER") → #<PACKAGE "COMMON-LISP-USER">
(export (intern "CONTRABAND" (make-package ’temp)) ’temp) → T
(find-symbol "CONTRABAND") → NIL, NIL
(use-package ’temp) → T
(find-symbol "CONTRABAND") → CONTRABAND, :INHERITED
(unexport ’contraband ’temp) → T
(find-symbol "CONTRABAND") → NIL, NIL
Side Effects:
Package system is modified.
Affected By:
Current state of the package system.
Exceptional Situations:
If unexport is given a symbol not accessible in package at all, an error of type package-error is signaled.
The consequences are undefined if package is the KEYWORD package or the COMMON-LISP package.
See Also:
export, Section 11.1 (Package Concepts)
Expanded Reference: unexport
Basic Usage: Reverting a Symbol to Internal Status
unexport changes an external symbol back to internal status. It undoes the effect of export.
(defpackage "SVC" (:use) (:export "PUBLIC-FN"))
(find-symbol "PUBLIC-FN" "SVC")
;; => SVC:PUBLIC-FN
;; => :EXTERNAL
(unexport (find-symbol "PUBLIC-FN" "SVC") "SVC")
;; => T
(find-symbol "PUBLIC-FN" "SVC")
;; => SVC::PUBLIC-FN
;; => :INTERNAL
Inherited Symbols Become Inaccessible After Unexport
When a symbol is unexported, packages that were inheriting it can no longer see it.
(defpackage "LIB-U" (:use) (:export "HELPER"))
(defpackage "APP-U" (:use "LIB-U"))
(find-symbol "HELPER" "APP-U")
;; => LIB-U:HELPER
;; => :INHERITED
(unexport (find-symbol "HELPER" "LIB-U") "LIB-U")
;; => T
(find-symbol "HELPER" "APP-U")
;; => NIL
;; => NIL
Unexporting an Already-Internal Symbol is a No-Op
(defpackage "INT-PKG" (:use))
(intern "SECRET" "INT-PKG")
(find-symbol "SECRET" "INT-PKG")
;; => INT-PKG::SECRET
;; => :INTERNAL
;; Already internal, so unexport does nothing special
(unexport (find-symbol "SECRET" "INT-PKG") "INT-PKG")
;; => T
(find-symbol "SECRET" "INT-PKG")
;; => INT-PKG::SECRET
;; => :INTERNAL
Unexporting Multiple Symbols
unexport accepts a list of symbols.
(defpackage "MULTI-U" (:use) (:export "A" "B" "C"))
(unexport (list (find-symbol "A" "MULTI-U")
(find-symbol "B" "MULTI-U"))
"MULTI-U")
=> T
(find-symbol "A" "MULTI-U")
;; => MULTI-U::A
;; => :INTERNAL
(find-symbol "B" "MULTI-U")
;; => MULTI-U::B
;; => :INTERNAL
(find-symbol "C" "MULTI-U")
;; => MULTI-U:C
;; => :EXTERNAL