From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: gv-exander for 'list' Date: Tue, 19 Mar 2019 14:41:26 -0400 Message-ID: References: <87bm26stsj.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="215202"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 19 19:43:52 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6JiJ-000trC-TG for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2019 19:43:52 +0100 Original-Received: from localhost ([127.0.0.1]:33361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6JiI-0007aJ-Ou for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2019 14:43:50 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6JgI-0006lm-AL for emacs-devel@gnu.org; Tue, 19 Mar 2019 14:41:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6JgG-0000fS-MG for emacs-devel@gnu.org; Tue, 19 Mar 2019 14:41:46 -0400 Original-Received: from [195.159.176.226] (port=38008 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h6JgD-0000ZR-7E for emacs-devel@gnu.org; Tue, 19 Mar 2019 14:41:42 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1h6Jg5-000rMl-7n for emacs-devel@gnu.org; Tue, 19 Mar 2019 19:41:33 +0100 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:CLtLoe7Xi5xF4eadHX9VbVfZuC0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:234377 Archived-At: > while I was trying to understand the "debatable" gv expanders (`if', > `cond' etc.) I had the idea of adding an expander for `list': [ Ahem! `if` and `cond` aren't in the "debatable" category. `cons` and logand` are! BTW, I think the unifying "feature" of the debatable category is that these GVs impose constraints on the value that can be assigned. ] > +(put 'list 'gv-expander > + (lambda (do &rest elt-places) > + ;; FIXME: when using this with letf people would expect this to > + ;; create local bindings Not sure what you mean by this FIXME. > + (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)))))))) This expands to incorrect code: (macroexpand '(setf (list a b) x)) You should probably replace `macroexp-copyable-p` with `ignore`. > 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? I don't see why it wouldn't do what you say, but I'm not sure how often that would be usable (and preferable to an alternative). Also, as a replacement for cl-progv it will suffer from the fact that instead of using the built-in C code for dynamic scoping, it will mimic it via unwind-protect, which means that it will misbehave in the presence of buffer-local values: (let ((buf (current-buffer))) (with-temp-buffer (setq default-directory "/bar/") (cl-letf (((list default-directory) '("/foo/"))) (set-buffer buf)))) There are a few other similar cases that we slowly patched over the years ;-) [ Note that it's one of the reasons (beside efficiency) why `cl-letf` is careful to treat simple variables specially, thus taking advantage of the built-in handling of dynamically-scoped vars. ] Stefan