* lisp/subr.el (member-if): Fix compiler macro multiple evaluation.

Problem reported by Pip Cet <pipcet@protonmail.com>.
This commit is contained in:
Sean Whitton
2026-03-22 16:03:16 +00:00
parent c96c89faaa
commit 17a3f6bf99
2 changed files with 12 additions and 3 deletions

View File

@@ -1226,8 +1226,13 @@ with
(member-if (lambda (x) (foo (bar x))) items)"
(declare (compiler-macro
(lambda (_)
(let ((x (make-symbol "x")))
`(drop-while (lambda (,x) (not (funcall ,pred ,x))) ,list)))))
(let* ((x (make-symbol "x"))
(f (and (not (internal--effect-free-fun-arg-p pred))
(make-symbol "f")))
(form `(drop-while (lambda (,x)
(not (funcall ,(or f pred) ,x)))
,list)))
(if f `(let ((,f ,pred)) ,form) form)))))
(drop-while (lambda (x) (not (funcall pred x))) list))
;; This is good to have for improved readability in certain uses, but

View File

@@ -1725,7 +1725,11 @@ The argument names are important."
(let ((xs (number-sequence 0 4)))
(dotimes (x (1+ (length xs)))
(should (eq (subr-tests--any-memql x xs)
(memql x xs))))))
(memql x xs)))))
(let ((n 0))
(any (prog1 (lambda (x) (eq x 5)) (incf n))
(number-sequence 0 4))
(should (eq n 1))))
(ert-deftest total-line-spacing ()
(progn