diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-11-14 07:19:41 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-11-14 07:19:41 -0800 |
commit | 32385342eaa73711cbd2d3481ecd98969bb382ef (patch) | |
tree | 9d3daba823213b63976aed07bcaa6ca091d7f1e1 | |
parent | fe43a541f9a5eaee27ff2ce2811cfd83eb6e3b1c (diff) | |
download | txr-32385342eaa73711cbd2d3481ecd98969bb382ef.tar.gz txr-32385342eaa73711cbd2d3481ecd98969bb382ef.tar.bz2 txr-32385342eaa73711cbd2d3481ecd98969bb382ef.zip |
New in-package macro.
* lisplib.c (package_set_entries): Add in-package
symbol name to autload list.
* share/txr/stdlib/package.tl (in-package): New macro.
* txr.1: Documented.
-rw-r--r-- | lisplib.c | 2 | ||||
-rw-r--r-- | share/txr/stdlib/package.tl | 7 | ||||
-rw-r--r-- | txr.1 | 25 |
3 files changed, 33 insertions, 1 deletions
@@ -410,7 +410,7 @@ static val getopts_instantiate(val set_fun) static val package_set_entries(val dlt, val fun) { val name[] = { - lit("defpackage"), + lit("defpackage"), lit("in-package"), nil }; set_dlt_entries(dlt, name, fun); diff --git a/share/txr/stdlib/package.tl b/share/txr/stdlib/package.tl index 1827628f..7e62b6e5 100644 --- a/share/txr/stdlib/package.tl +++ b/share/txr/stdlib/package.tl @@ -81,3 +81,10 @@ ,*(unless (assoc :use clauses) ^((use-package "usr" ,pkg))) ,*exp-clauses ,pkg))) + +(defmacro in-package (pkg) + (unless (or (symbolp pkg) (stringp pkg)) + (throwf 'eval-error "~s: ~s isn't a package name" 'in-package pkg)) + ^(set *package* (or (find-package ',pkg) + (throwf 'eval-error "~s: no such package: ~s" + 'in-package ',pkg)))) @@ -39797,6 +39797,31 @@ removed with and the name is interned again. .RE +.coNP Macro @ in-package +.synb +.mets (in-package << name ) +.syne +.desc +The +.code in-package +macro causes the +.code *package* +special variable to take on the package denoted by +.metn name . +The macro checks, at expansion time, that +.meta name +is either a string or symbol. An error is thrown if +this isn't the case. + +The +.meta name +argument expression isn't evaluated, and so must not be quoted. + +The code generated by the macro performs a search for the +package; if the package is not found at the time when +the macro's expansion is evaluated. An error is thrown if +the package isn't found. + .SS* Pseudo-random Numbers .coNP Special variable @ *random-state* .desc |