From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: master b72f885: Make dlet work like let, not let* Date: Tue, 21 Sep 2021 09:50:16 +0200 Message-ID: <874kaetip8.fsf@gnu.org> References: <83wnp5m9i5.fsf@gnu.org> <87y27rhwp0.fsf@gnu.org> <878rzqtopk.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4033"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.6; emacs 28.0.50 Cc: emacs-devel@gnu.org To: Jean Louis Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 21 10:52:40 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 1mSbW3-0000o1-Jv for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Sep 2021 10:52:39 +0200 Original-Received: from localhost ([::1]:41838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSbW2-0004Sv-7F for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Sep 2021 04:52:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSbV5-0003JN-DV for emacs-devel@gnu.org; Tue, 21 Sep 2021 04:51:39 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34378) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSbV3-00026f-BJ; Tue, 21 Sep 2021 04:51:38 -0400 Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:49363) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSbV0-0007DD-VP; Tue, 21 Sep 2021 04:51:37 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailauth.nyi.internal (Postfix) with ESMTP id EC68A27C0054; Tue, 21 Sep 2021 04:51:33 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 21 Sep 2021 04:51:33 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeigedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpehffgfhvffuffgjkfggtgesthdtre dttdertdenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhsughhsehgnhhurdho rhhgqeenucggtffrrghtthgvrhhnpeevveeikeetkeeviefgfeffiedvteeguddvffeuue duveegtddthedvhfeuveffhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpehthhhorhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhith ihqdekieejfeekjeekgedqieefhedvleekqdhtshguhheppehgnhhurdhorhhgsehfrghs thhmrghilhdrfhhm X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Sep 2021 04:51:32 -0400 (EDT) In-reply-to: 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:275210 Archived-At: Jean Louis 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