summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/struct.tl9
1 files changed, 9 insertions, 0 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl
index c9d19e91..bc463274 100644
--- a/share/txr/stdlib/struct.tl
+++ b/share/txr/stdlib/struct.tl
@@ -236,3 +236,12 @@
(defmacro defmeth (type-sym name arglist . body)
^(sys:defmeth ',type-sym ',name (lambda ,arglist
(block ,name ,*body))))
+
+(defmacro with-slots ((. slot-specs) obj-expr . body)
+ (with-gensyms (obj-sym)
+ ^(let ((,obj-sym ,obj-expr))
+ (symacrolet (,*(mapcar [iff consp
+ (aret ^(,@1 (slot ,obj-sym ',@2)))
+ (ret ^(,@1 (slot ,obj-sym ',@1)))]
+ slot-specs))
+ ,*body))))