[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gv-exander for 'list'

From: Michael Heerdegen
Subject: gv-exander for 'list'
Date: Tue, 19 Mar 2019 17:39:08 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)


while I was trying to understand the "debatable" gv expanders (`if',
`cond' etc.) I had the idea of adding an expander for `list':

From 85f6743d1f5f32305da298717279491067dddb0f Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <address@hidden>
Date: Tue, 19 Mar 2019 17:31:53 +0100
Subject: [PATCH] * lisp/emacs-lisp/gv.el: Add gv-expander for `list'

 lisp/emacs-lisp/gv.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index 4ea3ce84fc..4737f8df90 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -519,6 +519,21 @@ gv-delay-error
                               ,(funcall asetter `(car ,v))
                               ,(funcall dsetter `(cdr ,v)))))))))

+(put 'list 'gv-expander
+     (lambda (do &rest elt-places)
+       ;; FIXME: when using this with letf people would expect this to
+       ;; create local bindings
+       (let ((getters+setters
+              (mapcar (lambda (place)
+                        (gv-get place (lambda (g s) (cons g s))))
+                      elt-places)))
+         (funcall do `(list ,@(mapcar #'car getters+setters))
+                  (lambda (v)
+                    (macroexp-let2 macroexp-copyable-p v v
+                      (macroexp-progn
+                       (mapcar (lambda (x) (funcall (cdr x) `(pop ,v)))
+                               getters+setters))))))))
 (put 'logand 'gv-expander
      (lambda (do place &rest masks)
        (gv-letplace (getter setter) place

It could be an alternative to `progv', where the variable list isn't
computed dynamically (the values list still is), but OTOH allows
generalized variables.  Would that make sense?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]