summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-01-25 10:57:12 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-01-25 10:57:12 -0800
commitc485146a246ab4b69e6ec510ec47713897f4d463 (patch)
tree3e22b6ac0f756258851a0e280dac9aeb012931c9
parent41ea4bd2c8791696525aadb0a457ba36fa1d204e (diff)
downloadtxr-c485146a246ab4b69e6ec510ec47713897f4d463.tar.gz
txr-c485146a246ab4b69e6ec510ec47713897f4d463.tar.bz2
txr-c485146a246ab4b69e6ec510ec47713897f4d463.zip
New handle* macro, analogous to catch*.
* share/txr/stdlib/except.tl (sys:expand-handle): New function. (handle): Use sys:expand-handle to expand arguments. The previously unused :whole form argument is now put to use, and correctly captured using :form rather than :whole. (handle*): New macro. * txr.1: Documented.
-rw-r--r--share/txr/stdlib/except.tl16
-rw-r--r--txr.116
2 files changed, 27 insertions, 5 deletions
diff --git a/share/txr/stdlib/except.tl b/share/txr/stdlib/except.tl
index abba8bdb..0f81e763 100644
--- a/share/txr/stdlib/except.tl
+++ b/share/txr/stdlib/except.tl
@@ -38,8 +38,9 @@
(let ((catch-syms [mapcar car catch-clauses]))
^(sys:catch ,catch-syms ,try-form ,*catch-clauses)))
-(defmacro handle (:whole form try-form . handle-clauses)
- (let* ((exc-sym (gensym))
+(defun sys:expand-handle (form try-form handle-clauses)
+ (let* ((oper (car form))
+ (exc-sym (gensym))
(exc-args (gensym))
(syms-fragments (collect-each ((hc handle-clauses))
(tree-case hc
@@ -47,8 +48,9 @@
(unless (symbolp name)
(sys:handle-bad-syntax hc))
(list name ^(apply (lambda ,arglist ,*body)
- ,*(if (and (plusp sys:compat)
- (<= 161 sys:compat))
+ ,*(if (or (eq oper 'handle*)
+ (and (plusp sys:compat)
+ (<= 161 sys:compat)))
^(,exc-sym))
,exc-args)))
(else (sys:handle-bad-syntax hc))))))
@@ -59,5 +61,11 @@
,[mapcar car syms-fragments]
,try-form)))
+(defmacro handle (:form form try-form . handle-clauses)
+ (sys:expand-handle form try-form handle-clauses))
+
+(defmacro handle* (:form form try-form . handle-clauses)
+ (sys:expand-handle form try-form handle-clauses))
+
(defmacro ignwarn (. forms)
^(handler-bind (lambda (exc-sym arg) (throw 'continue)) (warning) ,*forms))
diff --git a/txr.1 b/txr.1
index 4abfebb1..d21cdbd3 100644
--- a/txr.1
+++ b/txr.1
@@ -33315,10 +33315,12 @@ exception search as if it didn't exist. When the handler function terminates,
either via a normal return or a nonlocal control transfer, then the handler is
re-enabled.
-.coNP Macro @ handle
+.coNP Macros @ handle and @ handle*
.synb
.mets (handle < try-expression
.mets \ \ >> {( symbol <> ( arg *) << body-form *)}*)
+.mets (handle* < try-expression
+.mets \ \ >> {( symbol >> ( type-arg << arg *) << body-form *)}*)
.syne
.desc
The
@@ -33370,6 +33372,18 @@ via
.code return
or throwing an exception.
+The
+.code handle*
+macro is a variant of
+.code handle
+with the following difference: when
+.code handle*
+invokes a clause, it passes the exception symbol as the leftmost argument
+.metn type-arg .
+Then the exception arguments follow. In contrast,
+only the exception arguments are passed to the clauses of
+.codn handle .
+
.coNP Macro @ with-resources
.synb
.mets (with-resources >> ({ sym >> [ init-form <> [ cleanup-form ])}*)