diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-01-25 10:29:27 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-01-25 10:29:27 -0800 |
commit | 41ea4bd2c8791696525aadb0a457ba36fa1d204e (patch) | |
tree | 8d006ed8212c8911d5542cb75808a5c5e26dafd3 /share | |
parent | 12454b0e43160c851e20614ce888d33c2f8d9b16 (diff) | |
download | txr-41ea4bd2c8791696525aadb0a457ba36fa1d204e.tar.gz txr-41ea4bd2c8791696525aadb0a457ba36fa1d204e.tar.bz2 txr-41ea4bd2c8791696525aadb0a457ba36fa1d204e.zip |
New catch*, giving access to exception symbol.
* eval.c (op_catch): The sys:catch operator now passes the
exception symbol as the first argument of each clause.
This means the catch macro must be adjusted.
* share/txr/stdlib/except.tl (catch): Macro now inserts
a gensym dummy first argument into each clause to take the
symbol passed by the sys:catch operator.
(catch*): New macro, which is identical to the previous
catch macro, and thus exposes the symbol passed as the
first argument.
* txr.1: Documented catch*.
* tests/012/struct.tl: Some gensym numbers need adjusting
in one test case.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/except.tl | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/share/txr/stdlib/except.tl b/share/txr/stdlib/except.tl index 17055207..abba8bdb 100644 --- a/share/txr/stdlib/except.tl +++ b/share/txr/stdlib/except.tl @@ -27,9 +27,16 @@ (defun sys:handle-bad-syntax (item) (throwf 'eval-error "~s: bad clause syntax: ~s" 'handle item)) -(defmacro catch (try-form . handle-clauses) - (let ((catch-syms [mapcar car handle-clauses])) - ^(sys:catch ,catch-syms ,try-form ,*handle-clauses))) +(defmacro catch (:form form try-form . catch-clauses) + (let ((catch-syms [mapcar car catch-clauses]) + (sys-catch-clauses (mapcar (do mac-param-bind @1 (type args . body) @1 + ^(,type (,(gensym) ,*args) ,*body)) + catch-clauses))) + ^(sys:catch ,catch-syms ,try-form ,*sys-catch-clauses))) + +(defmacro catch* (try-form . catch-clauses) + (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)) |