From cf4dba3899eef0a88bf4032bec5cf45c56a77077 Mon Sep 17 00:00:00 2001 From: Daanturo Date: Thu, 17 Nov 2022 13:57:20 +0700 Subject: [PATCH] Define macro dlet* * lisp/subr.el: implementation. * doc/lispref/variables.texi: documentation. * etc/NEWS: announce it, also add dlet's non-backward compatible breakage. --- doc/lispref/variables.texi | 8 ++++++++ etc/NEWS | 10 ++++++++++ lisp/subr.el | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 7206f2acd2..c574ffaf09 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -303,6 +303,14 @@ Binding}), but it's impractical to @code{defvar} these variables. the forms, and then make the variables non-special again. @end defspec +@defspec dlet* (bindings@dots{}) forms@dots{} +This form is like @code{dlet}, but each valueform can refer to the +symbols already bound previously, like what @code{let*} is to +@code{let} (actually this is Emacs 28's old @code{dlet}, as from Emacs +29 it no longer let bindings refer to the preceding symbols in this +same form). +@end defspec + @defspec named-let name bindings &rest body This special form is a looping construct inspired from the Scheme language. It is similar to @code{let}: It binds the variables in diff --git a/etc/NEWS b/etc/NEWS index 0b8f4539f9..1e9b1ce279 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2913,6 +2913,10 @@ when visiting JSON files. * Incompatible Lisp Changes in Emacs 29.1 ++++ +** dlet now uses let internally instead of let*. +--- + +++ ** 'format-prompt' now uses 'substitute-command-keys'. This means that both the prompt and 'minibuffer-default-prompt-format' @@ -3269,6 +3273,12 @@ The following generalized variables have been made obsolete: * Lisp Changes in Emacs 29.1 + ++++ +** New macro 'dlet*'. +Like what 'let*' is to 'let', functionally identical to the old 'dlet' +in Emacs 28. + +++ ** Interpreted closures are "safe for space". As was already the case for byte-compiled closures, instead of capturing diff --git a/lisp/subr.el b/lisp/subr.el index 6b83196d05..ddc48b554e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2155,6 +2155,14 @@ all symbols are bound before any of the VALUEFORMs are evalled." binders) (let ,binders ,@body))) +(defmacro dlet* (binders &rest body) + "Like `let*' but using dynamic scoping." + (declare (indent 1) (debug let)) + `(let (_) + ,@(mapcar (lambda (binder) + `(defvar ,(if (consp binder) (car binder) binder))) + binders) + (let ,binders ,@body))) (defmacro with-wrapper-hook (hook args &rest body) "Run BODY, using wrapper functions from HOOK with additional ARGS. -- 2.38.1