From f8bca2bc1e7bdb6fde4e61f92fa7b8e6f2295474 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 10 Aug 2023 19:25:36 -0700 Subject: 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. --- tests/012/use-as.tl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/012/use-as.tl (limited to 'tests/012/use-as.tl') 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) -- cgit v1.2.3