From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Alfred M. Szmidt" Newsgroups: gmane.emacs.devel Subject: Re: Is this a bug in while-let or do I missunderstand it? Date: Tue, 12 Nov 2024 12:55:33 -0500 Message-ID: References: <867c98svl0.fsf@fastmail.fm> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29228"; mail-complaints-to="usenet@ciao.gmane.io" Cc: arthur.miller@live.com, emacs-devel@gnu.org To: Joost Kremers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 12 18:56:15 2024 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 1tAv7f-0007TD-1Q for ged-emacs-devel@m.gmane-mx.org; Tue, 12 Nov 2024 18:56:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAv74-0000fN-9q; Tue, 12 Nov 2024 12:55:38 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAv72-0000eu-Qr for emacs-devel@gnu.org; Tue, 12 Nov 2024 12:55:36 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAv72-0008Ew-8a; Tue, 12 Nov 2024 12:55:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Date:References:Subject:In-Reply-To:To:From: mime-version; bh=UxzilT6UwStsFFwZolbnr3VmoiMt3GChsAtx+jPAUFs=; b=WLe8ki33t4LV DGeBeuoOlOM0sA4lqfyAoGPnBRGdiqDxGAfqNvEUljjR7QPbs+v/MFX/B5YKeTsn2qD/SVVdbrjjR JA7N0zJMw1M9byhzPM5DKtFYgn0viLdh+2JBXGsJ3/8dHCG8sYE3CxX26u2Ivb89Ao6704gIynP9Y IDtxPHJvJEkkIvB/IV8nd7rMLtuq0Tss/FLO7lqrVzEX/yrZAmaxTOkMWQlSgZ2dVasqPoILfA1hX yFemGiQT1SoH23YDDZUZihycU8nY0gDi5+bM307Fjayd2GanKpTjWuGw7u8fj/a2VTPNEK31ZKZqA eVs0Mrhzz1BqBHJb2Y+yBQ==; Original-Received: from ams by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1tAv6z-0005yS-9I; Tue, 12 Nov 2024 12:55:33 -0500 In-Reply-To: <867c98svl0.fsf@fastmail.fm> (message from Joost Kremers on Tue, 12 Nov 2024 09:30:19 +0100) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325434 Archived-At: > The scope of the let-binding is the same in both. I don't see how. With `while`, `result` is let-bound outside the loop, with `while-let` it's bound inside the loop, even after macroexpanding it: And that is (again) the crux of the matter, one group thinks it is LET bound outside of the loop, another inside. Consider this, which will pass nil to BAR, but also reassign RESULT to whatever FOO returns each iteration; which is the part that is confusing for those who consider LET to be the binding and scope of the variables (this also makes it much harder to debug code I think). (while-let ((result (foo))) (setq result nil) (bar result)) Which expands to: (catch 'done18 (while t (let* ((result (and t (foo)))) (if result (progn (setq result nil) (bar result)) (throw 'done18 nil))))) Mind you, what you want to do can still be done with `while-let`, provided you establish the relevant binding *outside* the loop: Then what point is while-let? Should there be a let-while? And a let-while-let? There are 20 occurences of while-let in Emacs ...