unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Toby Cubitt <toby@dr-qubit.org>
To: 47272@debbugs.gnu.org
Subject: bug#47272: 27.1; cl-progv binds variables in wrong order
Date: Sat, 20 Mar 2021 00:27:03 +0000	[thread overview]
Message-ID: <20210320002701.GA23146@bb84.Home> (raw)



The following

(cl-progv (test test) (1 2)
  test)

evaluates to 1. It should evaluate to 2.

The docstring states that cl-progv "much like a let form", and

(let ((test 1) (test 2))
 test)

evaluates to 2.


This bug in cl-progv breaks org agenda settings in
org-agenda-custom-commands, by preventing local variable settings in
agenda blocks from overriding variable settings in the overall agenda
command. (Broken since commit 129c33dddfa80202f23756ad5b513acdc036591c
in the org-mode repo, which switched the agenda varable setting code in
org-agenda to use cl-progv.)


Fixed implementation of cl-progv:

(defmacro cl-progv (symbols values &rest body)
  "Bind SYMBOLS to VALUES dynamically in BODY.
The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists.
Each symbol in the first list is bound to the corresponding value in the
second list (or to nil if VALUES is shorter than SYMBOLS); then the
BODY forms are executed and their result is returned.  This is much like
a `let' form, except that the list of symbols can be computed at run-time."
  (declare (indent 2) (debug (form form body)))
  (let ((bodyfun (make-symbol "body"))
        (binds (make-symbol "binds"))
        (syms (make-symbol "syms"))
        (vals (make-symbol "vals")))
    `(progn
       (let* ((,syms ,symbols)
              (,vals ,values)
              (,bodyfun (lambda () ,@body))
              (,binds ()))
         (while ,syms
           (push (list (pop ,syms) (list 'quote (pop ,vals))) ,binds))
	 (setq ,binds (nreverse ,binds))
         (eval (list 'let ,binds (list 'funcall (list 'quote ,bodyfun))))))))

--
Dr T. S. Cubitt
Reader (Associate Professor) in Quantum Information
Royal Society University Research Fellow
Department of Computer Science
University College London

email: tsc25@cantab.net
web:   www.dr-qubit.org







             reply	other threads:[~2021-03-20  0:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20  0:27 Toby Cubitt [this message]
2021-03-20  9:01 ` bug#47272: 27.1; cl-progv binds variables in wrong order Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210320002701.GA23146@bb84.Home \
    --to=toby@dr-qubit.org \
    --cc=47272@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).