summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kyheku <kaz@kylheku.com>2020-01-15 21:22:44 -0800
committerKaz Kyheku <kaz@kylheku.com>2020-01-15 21:22:44 -0800
commit586a4afc8f9d5616fdf21c471a772391e574bc43 (patch)
tree97e85b30233acc121442731a5512660dbab129bd /share
parent267802c97c4a19354647eb96893429d5c67214df (diff)
downloadtxr-586a4afc8f9d5616fdf21c471a772391e574bc43.tar.gz
txr-586a4afc8f9d5616fdf21c471a772391e574bc43.tar.bz2
txr-586a4afc8f9d5616fdf21c471a772391e574bc43.zip
with-resources: support multiple cleanup forms.
* share/txr/stdlib/with-resources.tl (with-resources): Rearrange tree-case cases to recognize a sequence of cleanup forms and insert into the output accordingly. * txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/with-resources.tl10
1 files changed, 5 insertions, 5 deletions
diff --git a/share/txr/stdlib/with-resources.tl b/share/txr/stdlib/with-resources.tl
index eb061066..5c1b8130 100644
--- a/share/txr/stdlib/with-resources.tl
+++ b/share/txr/stdlib/with-resources.tl
@@ -26,15 +26,15 @@
(defmacro with-resources (:form f res-bindings . body)
(tree-case res-bindings
- (((sym init cleanup) . rest)
+ (((sym init) . rest)
+ ^(let ((,sym ,init))
+ (with-resources ,rest ,*body)))
+ (((sym init . cleanup) . rest)
^(let ((,sym ,init))
(when ,sym
(unwind-protect
(with-resources ,rest ,*body)
- ,cleanup))))
- (((sym init) . rest)
- ^(let ((,sym ,init))
- (with-resources ,rest ,*body)))
+ ,*cleanup))))
((sym . rest)
^(let (,sym)
(with-resources ,rest ,*body)))