emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master b72f885: Make dlet work like let, not let*


From: Jean Louis
Subject: Re: master b72f885: Make dlet work like let, not let*
Date: Tue, 21 Sep 2021 10:17:39 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Tassilo Horn <tsdh@gnu.org> [2021-09-21 09:42]:
> where the binding of languages_extension and area_id can access the new
> value of the defvar wrs::variables (because of let*) but
> languages_extension and area_id are only bound lexically (because they
> are not defvar-ed and should not because of their missing prefix)
> meaning they are bound only in the body of this `let*' (lexically!) but
> not in `do-stuff' when it is called in this `let*'s body.  So for those,
> you really need dlet.  Assuming that area_id never depends on the value
> of languages_extension etc, you probably can use
> 
> (defvar wrs::variables nil)
> 
> (let ((wrs::variables ...))
>   (dlet ((languages_extension (gethash "languages_extension" wrs::variables))
>          (area_id (gethash "area_id" wrs::variables)))
>     (do-stuff)))

Thanks, those are good pointers. 

Though I did not explain everything. `dlet' is (was) used on my side
to interpolate bunch of information. Variables are also fetched from
the database and interpolated. In general there are too many issues
that I would need to refactor and think about it now, which is not
necessary. This gave me enough time waste.

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)))

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. 

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.

Instead I will just use the modified macro for myself, which does what
`dlet' was doing before August 1st 2021.


Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]