diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-08-20 20:10:43 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-08-20 20:10:43 -0700 |
commit | 0689691933695945e2f8f4ddd160da958bde936f (patch) | |
tree | 726a5d0d5f4dcd8eeae6d1845bb66357866679b8 | |
parent | 607f0d271211e37d96ce7ba50a3f69372c000779 (diff) | |
download | txr-0689691933695945e2f8f4ddd160da958bde936f.tar.gz txr-0689691933695945e2f8f4ddd160da958bde936f.tar.bz2 txr-0689691933695945e2f8f4ddd160da958bde936f.zip |
New function: intern-fb.
To accompany find-symbol-fb, there is intern-fb, which is like
intern, but searches the fallback list.
* eval.c (eval_init): Register intern-fb intrinsic.
* lib.c (intern_fallback_intrinsic): New function. Does
defaulting and error checks, then calls intern_fallback, just
like intern_intrinsic calls intern.
* lib.h (intern_fallback_intrinsic): Declared.
* txr.1: Documented.
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 11 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 26 |
4 files changed, 37 insertions, 2 deletions
@@ -6626,6 +6626,7 @@ void eval_init(void) reg_fun(intern(lit("use-package"), user_package), func_n2o(use_package, 1)); reg_fun(intern(lit("unuse-package"), user_package), func_n2o(unuse_package, 1)); reg_fun(intern(lit("intern"), user_package), func_n2o(intern_intrinsic, 1)); + reg_fun(intern(lit("intern-fb"), user_package), func_n2o(intern_fallback_intrinsic, 1)); reg_fun(intern(lit("unintern"), user_package), func_n2o(unintern, 1)); reg_fun(intern(lit("find-symbol"), user_package), func_n3o(find_symbol, 1)); reg_fun(intern(lit("find-symbol-fb"), user_package), func_n3o(find_symbol_fb, 1)); @@ -5532,6 +5532,17 @@ val intern_fallback(val str, val package) } } +val intern_fallback_intrinsic(val str, val package_in) +{ + val self = lit("intern-fallback"); + val package = get_package(self, package_in, nil); + + if (!stringp(str)) + uw_throwf(error_s, lit("~a: name ~s isn't a string"), self, str, nao); + + return intern_fallback(str, package); +} + val symbolp(val sym) { switch (type(sym)) { @@ -901,6 +901,7 @@ val package_foreign_symbols(val package); val package_fallback_list(val package); val set_package_fallback_list(val package, val list); val intern_fallback(val str, val package); +val intern_fallback_intrinsic(val str, val package_in); val symbolp(val sym); val symbol_name(val sym); val symbol_package(val sym); @@ -50364,7 +50364,10 @@ clause of the .code defpackage macro. The fallback package list plays a role only in three situations: one in the \*(TL parser, one in the printer, and one in the interactive -listener. +listener. Besides that, two library functions refer to it: +.code intern-fb +and +.codn find-symbol-fb . The parser situation involving the fallback list occurs when the \*(TL parser resolves an unqualified symbol token: a symbol token not carrying @@ -51004,7 +51007,7 @@ package objects. Strings are taken to be package names, which must resolve to existing packages. Symbols are reduced to strings via .codn symbol-name . -.coNP Function @ intern +.coNP Functions @ intern and @ intern-fb .synb .mets (intern < name <> [ package ]) .syne @@ -51033,6 +51036,25 @@ is created and inserted into and that symbol is returned. In this case, the package becomes the symbol's home package. +The +.code intern-fb +function is very similar to +.code intern +except that if the symbol is not found in +.meta package +then the packages listed in the fallback list of +.meta package +are searched, in order. Only these packages themselves are searched, +not their own fallback lists. If a symbol called +.meta name +is found, the search terminates and that symbol is returned. +Only if nothing is found in the fallback list will +.code intern-fb +create a new symbol and insert it into +.metn package , +exactly like +.codn intern . + .coNP Function @ unintern .synb .mets (unintern < symbol <> [ package ]) |