From c1d379d41a99aa61768536f6a5bd0b97d8519ce1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sat, 4 May 2024 14:09:23 +0200 Subject: [PATCH] Allow `letrec` binding without init expression For example, (letrec (... (x) ...) ...) is now allowed. * lisp/subr.el (letrec): Allow omitted init expression. * test/lisp/subr-tests.el (subr--tests-letrec): Add test case. (cherry picked from commit fd859fbea2e9d13e76db1c5295d9ddd1c5955d83) --- lisp/subr.el | 4 +++- test/lisp/subr-tests.el | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 8b222cee480..de5d5c72911 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2282,7 +2282,9 @@ all symbols are bound before any of the VALUEFORMs are evalled." (let ((nbody (if (null binders) (macroexp-progn body) `(let ,(mapcar #'car binders) - ,@(mapcar (lambda (binder) `(setq ,@binder)) binders) + ,@(mapcan (lambda (binder) + (and (cdr binder) (list `(setq ,@binder)))) + binders) ,@body)))) (cond ;; All bindings are recursive. diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 4e3f743cc93..119c124f3a5 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -744,7 +744,14 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350." (+ subr-tests-var1 subr-tests-var2))) '(let* ((subr-tests-var1 1) (subr-tests-var2 subr-tests-var1)) - (+ subr-tests-var1 subr-tests-var2))))) + (+ subr-tests-var1 subr-tests-var2)))) + ;; Check that the init expression can be omitted, as in `let'/`let*'. + (should (equal (letrec ((a (lambda () (funcall c))) + (b) + (c (lambda () b))) + (setq b 'ok) + (funcall a)) + 'ok))) (defvar subr-tests--hook nil) -- 2.39.5