[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master b72f885: Make dlet work like let, not let*
From: |
Tassilo Horn |
Subject: |
Re: master b72f885: Make dlet work like let, not let* |
Date: |
Tue, 21 Sep 2021 09:50:16 +0200 |
User-agent: |
mu4e 1.6.6; emacs 28.0.50 |
Jean Louis <bugs@gnu.support> writes:
> My temporary personal solution is simply to bring it back how it was
> and rename the macro to my own.
>
> (defmacro rcd-dlet (binders &rest body)
> "Like `let*' but using dynamic scoping."
> (declare (indent 1) (debug let))
> ;; (defvar FOO) only affects the current scope, but in order for
> ;; this not to affect code after the main `let' we need to create a new
> scope,
> ;; which is what the surrounding `let' is for.
> ;; FIXME: (let () ...) currently doesn't actually create a new scope,
> ;; which is why we use (let (_) ...).
> `(let (_)
> ,@(mapcar (lambda (binder)
> `(defvar ,(if (consp binder) (car binder) binder)))
> binders)
> (let* ,binders ,@body)))
Another variant would be like this which doesn't need to know the
mechanics of dlet but just creates a nested dlet:
(defmacro dlet* (bindings &rest body)
(declare (indent 1) (debug let))
(if bindings
`(dlet (,(car bindings))
(dlet* ,(cdr bindings)
,@body))
`(progn ,@body)))
> As a side note, the advise for variables to be first `defvar-ed' if
> they are to be used in `let*' is not practical. It increases work, it
> does not lessen the work.
The advice is to defvar variables which should be dynamically bound, and
to have few of them because dynamic scope is very hard to debug. So the
work saved at coding time might be invested when debugging later. ;-)
> You know when you start creating `let*' variables you don't want to
> think much, just do it. Now I am supposed to make 50-100 `defvar-ed'
> variables.
Well, it seems not to match your design. If I would try to build a
templating system I'd try to have just one defvar-ed wcr::variables and
access that when replacing the template placeholders rather than having
to dlet each and every thing inside vcr::variables.
Bye,
Tassilo
- Re: master b72f885: Make dlet work like let, not let*, Jean Louis, 2021/09/20
- Re: master b72f885: Make dlet work like let, not let*, Tassilo Horn, 2021/09/20
- Re: master b72f885: Make dlet work like let, not let*, Jean Louis, 2021/09/21
- Re: master b72f885: Make dlet work like let, not let*, Tassilo Horn, 2021/09/21
- Re: master b72f885: Make dlet work like let, not let*, Jean Louis, 2021/09/21
- Re: master b72f885: Make dlet work like let, not let*,
Tassilo Horn <=
- Re: master b72f885: Make dlet work like let, not let*, Jean Louis, 2021/09/21