diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-08-10 19:25:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-08-10 19:25:36 -0700 |
commit | f8bca2bc1e7bdb6fde4e61f92fa7b8e6f2295474 (patch) | |
tree | e9b5236aa162504a8701c7452938099996bcbe85 /tests/012/use-as.tl | |
parent | 174c054bbc54aefa4068d2863b43fabd9914ebd2 (diff) | |
download | txr-f8bca2bc1e7bdb6fde4e61f92fa7b8e6f2295474.tar.gz txr-f8bca2bc1e7bdb6fde4e61f92fa7b8e6f2295474.tar.bz2 txr-f8bca2bc1e7bdb6fde4e61f92fa7b8e6f2295474.zip |
New feature: local symbol renaming.
The new function use-sym-as can bring a foreign
symbol into a package under a different name,
which is not that symbol's name. This is also
featured in a new defpackage clause, :use-syms-as.
With this simple relaxation in the package system,
we don't require package local nicknames, which is
more complicated to implement and less ergonomic,
because it doesn't actually vanquish the use of
ugly package prefixes on clashing symbols.
* eval.c (eval_init): Register use-syms-as.
* lib.c (use_sym_as): New function, made out of
use_sym.
(use_sym): Now a wrapper for use_sym_as.
* lib.h (use_sym_as): Declared.
* stdlib/package.tl (defpackage): Implement :use-syms-as
clause.
* tests/012/use-as.tl: New file.
* txr.1: Documented,
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'tests/012/use-as.tl')
-rw-r--r-- | tests/012/use-as.tl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/012/use-as.tl b/tests/012/use-as.tl new file mode 100644 index 00000000..681a968d --- /dev/null +++ b/tests/012/use-as.tl @@ -0,0 +1,31 @@ +(load "../common") + +(defpackage lottery + (:local draw) + (:fallback usr)) + +(defpackage graphics + (:local draw) + (:fallback usr)) + +(defpackage gui-lottery + (:fallback lottery graphics usr pub) + (:use-syms-as lottery:draw ldraw + graphics:draw gdraw)) + +(in-package gui-lottery) + +(mtest + (package-name (symbol-package 'ldraw)) "lottery" + (package-name (symbol-package 'gdraw)) "graphics" + (symbol-name 'ldraw) "draw" + (symbol-name 'gdraw) "draw") + +(mtest + (tostring 'ldraw) "draw" + (tostring 'gdraw) "graphics:draw") + +(mtest + (use-sym-as 3 '#:foo) :error + (use-sym-as 'ldraw 3) :error + (use-sym-as 'x 'x) x) |