From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.devel Subject: Re: master b72f885: Make dlet work like let, not let* Date: Tue, 21 Sep 2021 10:17:39 +0300 Message-ID: References: <83wnp5m9i5.fsf@gnu.org> <87y27rhwp0.fsf@gnu.org> <878rzqtopk.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1492"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) Cc: emacs-devel@gnu.org To: Tassilo Horn Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 21 09:22:21 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mSa6f-0000B4-5n for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Sep 2021 09:22:21 +0200 Original-Received: from localhost ([::1]:46594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSa6d-0007IM-9K for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Sep 2021 03:22:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSa5S-0006a4-Iy for emacs-devel@gnu.org; Tue, 21 Sep 2021 03:21:06 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:57913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSa5O-0000Ck-1q; Tue, 21 Sep 2021 03:21:05 -0400 Original-Received: from localhost ([::ffff:41.210.154.92]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000005BE63.00000000614987DA.000045D3; Tue, 21 Sep 2021 00:20:57 -0700 Mail-Followup-To: Tassilo Horn , emacs-devel@gnu.org Content-Disposition: inline In-Reply-To: <878rzqtopk.fsf@gnu.org> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275201 Archived-At: * Tassilo Horn [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/