diff options
-rw-r--r-- | lib.c | 10 | ||||
-rw-r--r-- | tests/012/use-as.tl | 8 | ||||
-rw-r--r-- | txr.1 | 42 |
3 files changed, 60 insertions, 0 deletions
@@ -7359,6 +7359,16 @@ val unuse_sym(val symbol, val package_in) val visible = cdr(found_visible); val hidden = cdr(found_hidden); + if (!found_visible || visible != symbol) { + name = hash_revget(package->pk.symhash, symbol, eq_f, identity_f); + if (name) { + found_visible = gethash_e(self, package->pk.symhash, name); + found_hidden = gethash_e(self, package->pk.hidhash, name); + visible = cdr(found_visible); + hidden = cdr(found_hidden); + } + } + if (!found_visible || visible != symbol) return nil; diff --git a/tests/012/use-as.tl b/tests/012/use-as.tl index 681a968d..eb736d9d 100644 --- a/tests/012/use-as.tl +++ b/tests/012/use-as.tl @@ -29,3 +29,11 @@ (use-sym-as 3 '#:foo) :error (use-sym-as 'ldraw 3) :error (use-sym-as 'x 'x) x) + +(mtest + (find-symbol "ldraw") lottery:draw + (find-symbol "gdraw") graphics:draw + (unuse-sym 'ldraw) lottery:draw + (unuse-sym 'gdraw) graphics:draw + (find-symbol "ldraw") nil + (find-symbol "gdraw") nil) @@ -67308,6 +67308,15 @@ clauses and .codn :use-syms-as . +Note: +if +.code use-sym-as +is used to introduce a foreign symbol into a package under a different +name, that symbol cannot be removed with +.codn unintern . +It can only be removed using +.codn unuse-sym . + .coNP Function @ unuse-sym .synb .mets (unuse-sym < symbol <> [ package ]) @@ -67355,6 +67364,39 @@ then .meta symbol itself is returned. +There are close similarities between the function +.code unintern +and +.codn unuse-sym , +but the two are significantly different. + +Firstly, +.code unuse-sym +cannot be used to remove a symbol from its home package. As noted +above, this requires +.codn unintern . + +Secondly, +.code unuse-sym +can be used to undo the effect of +.code use-sym-as +whereby a foreign symbol is introduced into a package under a +different name. If +.meta symbol +is not found under its name, +.code unuse-sym +will search the package for that symbol to discover whether it is +present under a different name, and proceed with the removal +using that name. The +.code unintern +function performs no such secondary check; if +.meta symbol +is not found in the package under its own name, the operation fails, +and so +.code unintern +cannot be used for undoing the effect of +.codn use-sym-as . + .coNP Functions @ use-package and @ unuse-package .synb .mets (use-package < package-list <> [ package ]) |