summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-10 07:58:00 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-10 07:58:00 -0700
commit6aa141253aa8a9c0b8f93b38ac225eacfb93566c (patch)
tree9cbc351c56f4653333ba47293b56b1e3226dcd13 /share
parent35c830aa764e6e456530ed9d18ff5a686d10d96c (diff)
downloadtxr-6aa141253aa8a9c0b8f93b38ac225eacfb93566c.tar.gz
txr-6aa141253aa8a9c0b8f93b38ac225eacfb93566c.tar.bz2
txr-6aa141253aa8a9c0b8f93b38ac225eacfb93566c.zip
New macro: with-objects.
* lisplib.c (with_resources_set_entries): "with-objects" added to name table. * share/txr/stdlib/with-resources.tl (with-objects): New macro. * txr.1: Documented with-objects. Added note to :fini specifier of defstruct pointing to call-finalizers and with-objects.
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))))))