From 69a5f6d3582c0208d2b7c8b3036cdfd6729e88f2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 14 Nov 2016 07:19:41 -0800 Subject: 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. --- lisplib.c | 2 +- share/txr/stdlib/package.tl | 7 +++++++ txr.1 | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lisplib.c b/lisplib.c index 38c002ce..713bb480 100644 --- a/lisplib.c +++ b/lisplib.c @@ -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)))) diff --git a/txr.1 b/txr.1 index 27fa0cae..b692d6f0 100644 --- a/txr.1 +++ b/txr.1 @@ -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 -- cgit v1.2.3