diff options
-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 |