From 57fa015d03232e5517cb6d2082d24ef18ca88e24 Mon Sep 17 00:00:00 2001 From: Daanturo Date: Sat, 19 Nov 2022 12:02:35 +0700 Subject: [PATCH] Define macro dlet* * lisp/subr.el: implementation. * doc/lispref/variables.texi: documentation. * etc/NEWS: announce it. --- doc/lispref/variables.texi | 6 ++++++ etc/NEWS | 5 +++++ lisp/subr.el | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 7206f2acd2..11a0f220ca 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -303,6 +303,12 @@ Local 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}. +@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..11f9ccb26a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3269,6 +3269,11 @@ The following generalized variables have been made obsolete: * Lisp Changes in Emacs 29.1 + ++++ +** New macro 'dlet*'. +Like what 'let*' is to 'let'. + +++ ** 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..ecca52f99e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2155,6 +2155,14 @@ dlet 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