Question: How to unshadow symbol in a Common Lisp

Question

How to unshadow symbol in a Common Lisp

Answers 1
Added at 2017-01-04 08:01
Tags
Question

I've shadowed 'and symbol doing some experiments:

MATCHERS> (package-shadowing-symbols *package*)
(AND)

Neither (setf (package-shadowing-symbols *package*) nil) nor Slime don't work.

Answers
nr: #1 dodano: 2017-01-04 15:01

Alas, there is no non-destructive way to solve your problem: "shadowing" means that you have "something" (temp-pack::and) between the "light source" (cl:and) and the spot you are looking at (string "AND" below):

(let ((*package* (find-package '#:temp-pack)))
  (read-from-string "AND"))
=> TEMP-PACK::AND, 3

The only way out is to remove the obstacle blocking the light.

The modified example from shadow should be instructive:

(package-shadowing-symbols (make-package '#:temp-pack))
=> NIL
(find-symbol "AND" '#:temp-pack)
=> AND, :INHERITED
(shadow "AND" '#:temp-pack)
=> T
(find-symbol "AND" '#:temp-pack)
=> TEMP-PACK::AND, :INTERNAL
(package-shadowing-symbols '#:temp-pack)
=> (TEMP-PACK::AND)
(find-all-symbols "AND")
=> (:AND AND TEMP-PACK::AND)
(unintern 'temp-pack::and '#:temp-pack)
=> T
(find-all-symbols "AND")
=> (:AND AND)
(package-shadowing-symbols '#:temp-pack)
=> NIL

You have to actually unintern AND from TEMP-PACK because as long as it is interned there, it will be shadowing CL:AND.

Moreover, the trick of saving the symbol does not work:

(shadow "AND" '#:temp-pack)
=> T
(defparameter temp-pack-and 'temp-pack::and)
=> TEMP-PACK-AND
(unintern 'temp-pack::and '#:temp-pack)
=> T
(shadow "AND" '#:temp-pack)
=> T
temp-pack-and
=> #:AND
(eq temp-pack-and 'temp-pack::and)
=> NIL

This is because intern creates a new symbol:

If a symbol whose name is the same as string is already accessible in package, it is returned. If no such symbol is accessible in package, a new symbol with the given name is created and entered into package as an internal symbol

Source Show
◀ Wstecz