unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47272: 27.1; cl-progv binds variables in wrong order
@ 2021-03-20  0:27 Toby Cubitt
  2021-03-20  9:01 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Toby Cubitt @ 2021-03-20  0:27 UTC (permalink / raw)
  To: 47272



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







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

* bug#47272: 27.1; cl-progv binds variables in wrong order
  2021-03-20  0:27 bug#47272: 27.1; cl-progv binds variables in wrong order Toby Cubitt
@ 2021-03-20  9:01 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-03-20  9:01 UTC (permalink / raw)
  To: Toby Cubitt; +Cc: 47272

Toby Cubitt <toby@dr-qubit.org> writes:

> Fixed implementation of cl-progv:

Thanks; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-20  0:27 bug#47272: 27.1; cl-progv binds variables in wrong order Toby Cubitt
2021-03-20  9:01 ` Lars Ingebrigtsen

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).