shadowing-import
shadowing-import Function
Syntax:
shadowing-import 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:
shadowing-import is like import, but it does not signal an error even if the importation of a symbol would shadow some symbol already accessible in package.
shadowing-import inserts each of symbols into package as an internal symbol, regardless of whether another symbol of the same name is shadowed by this action. If a different symbol of the same name is already present in package, that symbol is first uninterned from package. The new symbol is added to package’s shadowing-symbols list.
shadowing-import does name-conflict checking to the extent that it checks whether a distinct existing symbol with the same name is accessible; if so, it is shadowed by the new symbol, which implies that it must be uninterned if it was present in package.
Examples:
(in-package "COMMON-LISP-USER") → #<PACKAGE "COMMON-LISP-USER">
(setq sym (intern "CONFLICT")) → CONFLICT
(intern "CONFLICT" (make-package ’temp)) → TEMP::CONFLICT, NIL
(package-shadowing-symbols ’temp) → NIL
(shadowing-import sym ’temp) → T
(package-shadowing-symbols ’temp) → (CONFLICT)
Side Effects:
shadowing-import changes the state of the package system in such a way that the consistency rules do not hold across the change.
package’s shadowing-symbols list is modified.
Affected By:
Current state of the package system.
See Also:
import, unintern, package-shadowing-symbols
Expanded Reference: shadowing-import
Basic Usage: Importing a Symbol and Adding It to the Shadowing List
shadowing-import is like import, but it does not signal a name conflict error. The imported symbol is added to the package's shadowing symbols list.
(defpackage "ORIGIN-SI" (:use) (:export "ITEM"))
(make-package "DEST-SI" :use '())
(intern "ITEM" "DEST-SI") ; a different symbol with the same name
(find-symbol "ITEM" "DEST-SI")
;; => DEST-SI::ITEM
;; => :INTERNAL
;; shadowing-import replaces DEST-SI::ITEM with ORIGIN-SI:ITEM
(shadowing-import (find-symbol "ITEM" "ORIGIN-SI") "DEST-SI")
;; => T
(find-symbol "ITEM" "DEST-SI")
;; => ORIGIN-SI:ITEM
;; => :INTERNAL
(package-shadowing-symbols "DEST-SI")
;; => (ORIGIN-SI:ITEM)
Resolving Name Conflicts Between Used Packages
shadowing-import is useful for resolving conflicts when two used packages export symbols with the same name.
(defpackage "A-SI" (:use) (:export "CLASH"))
(defpackage "B-SI" (:use) (:export "CLASH"))
(make-package "C-SI" :use '())
;; Import A's CLASH as the shadowing symbol before using both packages
(shadowing-import (find-symbol "CLASH" "A-SI") "C-SI")
(use-package '("A-SI" "B-SI") "C-SI")
=> T
(find-symbol "CLASH" "C-SI")
;; => A-SI:CLASH
;; => :INTERNAL
Difference from import
Regular import would signal an error if a different symbol with the same name is already accessible. shadowing-import silently replaces it.
(defpackage "NEW-SI" (:use))
(intern "THING" "NEW-SI")
;; Create an unrelated symbol to import
(defpackage "OTHER-SI" (:use) (:export "THING"))
;; import would signal an error here, but shadowing-import does not
(shadowing-import (find-symbol "THING" "OTHER-SI") "NEW-SI")
=> T
;; The old THING is gone, replaced by OTHER-SI's THING
(find-symbol "THING" "NEW-SI")
;; => OTHER-SI:THING
;; => :INTERNAL
The Symbol is Added to package-shadowing-symbols
(make-package "SHADOW-LIST-SI" :use '())
(package-shadowing-symbols "SHADOW-LIST-SI")
=> ()
(shadowing-import 'cl:car "SHADOW-LIST-SI")
=> T
(package-shadowing-symbols "SHADOW-LIST-SI")
=> (CAR)