summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-08-10 22:52:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-08-10 22:52:42 -0700
commitaf07e726a7573304b957a3712984f6ecf6167872 (patch)
tree15b7e2474ece8f3371c728d756e17d356906213e
parentf8bca2bc1e7bdb6fde4e61f92fa7b8e6f2295474 (diff)
downloadtxr-af07e726a7573304b957a3712984f6ecf6167872.tar.gz
txr-af07e726a7573304b957a3712984f6ecf6167872.tar.bz2
txr-af07e726a7573304b957a3712984f6ecf6167872.zip
unuse-sym: fix in face of use-sym-as.
* lib.c (unuse_sym): A used symbol may now appear in a package under a different name. So if we don't find a symbol under the symbol's name, or find a different symbol, we must try a reverse hash search before giving up. * txr.1: Add notes to use-sym-as that unuse-sym must be used to undo its effect. Add notes to unuse-sym discussing similarities and differences versus unintern. * tests/012/use-as.tl: New test cases.
-rw-r--r--lib.c10
-rw-r--r--tests/012/use-as.tl8
-rw-r--r--txr.142
3 files changed, 60 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index d7a7ce66..e5d01387 100644
--- a/lib.c
+++ b/lib.c
@@ -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)
diff --git a/txr.1 b/txr.1
index 9a7f8886..61355fff 100644
--- a/txr.1
+++ b/txr.1
@@ -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 ])