summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/with-resources.tl8
1 files changed, 8 insertions, 0 deletions
diff --git a/share/txr/stdlib/with-resources.tl b/share/txr/stdlib/with-resources.tl
index 50fc62a7..28cdd6fb 100644
--- a/share/txr/stdlib/with-resources.tl
+++ b/share/txr/stdlib/with-resources.tl
@@ -40,3 +40,11 @@
(nil
^(progn ,*body))
(other (error "with-resources: bad syntax"))))
+
+(defmacro with-objects (var-init-forms . body)
+ (let ((gens (mapcar (ret (gensym)) var-init-forms)))
+ ^(let ,gens
+ (unwind-protect
+ (let* ,(mapcar (aret ^(,@2 (set ,@1 ,@3))) gens var-init-forms)
+ ,*body)
+ ,*(reverse (mapcar (ret ^(call-finalizers ,@1)) gens))))))