unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* gv-exander for 'list'
@ 2019-03-19 16:39 Michael Heerdegen
  2019-03-19 18:41 ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Heerdegen @ 2019-03-19 16:39 UTC (permalink / raw)
  To: Emacs Development

[-- Attachment #1: Type: text/plain, Size: 140 bytes --]

Hello,

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-emacs-lisp-gv.el-Add-gv-expander-for-list.patch --]
[-- Type: text/x-diff, Size: 1448 bytes --]

From 85f6743d1f5f32305da298717279491067dddb0f Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
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
--
2.20.1


[-- Attachment #3: Type: text/plain, Size: 202 bytes --]


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?


Thanks,

Michael.

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-20 20:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-19 16:39 gv-exander for 'list' Michael Heerdegen
2019-03-19 18:41 ` Stefan Monnier
2019-03-19 22:34   ` Michael Heerdegen
2019-03-20  0:38     ` Stefan Monnier
2019-03-20 18:15       ` Michael Heerdegen
2019-03-20 19:06         ` Stefan Monnier
2019-03-20 20:03           ` Michael Heerdegen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).