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: Sat, 09 Nov 2024 11:33:45 -0500 Message-ID: References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5307"; mail-complaints-to="usenet@ciao.gmane.io" Cc: arthur.miller@live.com, emacs-devel@gnu.org To: Yuri Khan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 09 17:34:32 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 1t9oPw-0001Ff-Bd for ged-emacs-devel@m.gmane-mx.org; Sat, 09 Nov 2024 17:34:32 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9oPD-00074A-5b; Sat, 09 Nov 2024 11:33:47 -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 1t9oPB-00073w-Qs for emacs-devel@gnu.org; Sat, 09 Nov 2024 11:33:46 -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 1t9oPB-0008RK-Fj; Sat, 09 Nov 2024 11:33:45 -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=bp0QoZkHRW4aE56F84SFobISL9l3eqxrG0+HuI6OGUM=; b=gZDm+JRaCySU sXIjeHSvZlLGFE8hBxBCc9QiAd+caAgJBrg+CyOc0syanGaX+xO4tPdWcLQ7mZG37UP4Wu8LEno4x Qspeqa6nPeUaJ+sKH1h99e2mPtUhvRyTczMNWbuRTnLNu9IW66/Fjoto8YpORGdV+Y9cYS99T6geB kvggCwmAUNk5zW6Nvr2wpZNQiygRYFfPvinycQFl4nitft9CdDTrTw4ExPCtjVXDKr+j037W6fUV6 3GkbY1raxdZF0pSofB1S5Z79FaVi7kSxJGAfwrNNmk7VzLQ05n+Om830JUh9OsWsX/XEdVKcOz7lw rq01gG5C5sRS9DSvVb0FpA==; Original-Received: from ams by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1t9oPB-0003G7-83; Sat, 09 Nov 2024 11:33:45 -0500 In-Reply-To: (message from Yuri Khan on Sat, 9 Nov 2024 21:04:12 +0700) 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:325339 Archived-At: > If it wasn't clear, the unintuitive part is that while-let was to > establish the local environment, so that we don't need to type: > > (let ((som-var (init-form))) > (while some-var > ... )) But if it did it that way, the condition (init-form) would only be evaluated once, and I’d find *that* counterintuitive. Consider the usual form of a while loop: (while-let ((run (some-condition))) (message "running")) Do you expect that to evaluate (some-condition) once, then, if it’s initially true, run forever? That is how it is described in the manual, so yes (some-condition) should only be done once, and not every iteration. See (elisp) Conditionals . It can be convenient to bind variables in conjunction with using a conditional. It's often the case that you compute a value, and then want to do something with that value if it's non-‘nil’. The straightforward way to do that is to just write, for instance: (let ((result1 (do-computation))) (when result1 (let ((result2 (do-more result1))) (when result2 (do-something result2))))) Since this is a very common pattern, Emacs provides a number of macros to make this easier and more readable. The above can be written the following way instead: ... following the various with various FOO-let forms, ending with while-let.