From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Is this a bug in while-let or do I missunderstand it? Date: Sun, 10 Nov 2024 08:22:17 +0200 Message-ID: <86ldxrliau.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29857"; mail-complaints-to="usenet@ciao.gmane.io" Cc: ams@gnu.org, yuri.v.khan@gmail.com, emacs-devel@gnu.org To: arthur miller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 10 07:23:14 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 1tA1Lt-0007cK-Fk for ged-emacs-devel@m.gmane-mx.org; Sun, 10 Nov 2024 07:23:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tA1L5-00054D-P4; Sun, 10 Nov 2024 01:22:23 -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 1tA1L4-000544-Ta for emacs-devel@gnu.org; Sun, 10 Nov 2024 01:22:23 -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 1tA1L4-0000Rp-Gn; Sun, 10 Nov 2024 01:22:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Bsao0wUsJfntkbZOuzxoYfhYUAQORgQbbH2t7Kd8pyg=; b=HQlrHDDkR5Qg xYxIZXviGSgsYDL4nQ4kvqRr+j5GB6lzW7s5k3njfEz/sCe31O2Df4bJ3jmjEH2Lv1OsRMPnGZKW4 kRDFoJ4xW/6wp3IYAps4GQGT8klP7C95Z0ZL1xVKjeMsAxzFlAc+dAlPXM8ha/CglbtlKIry1P5+I C62LKncCyM5d1d9qPHz+s9AGhtN3DyINGSnXwcGhDPrYR4f6YW2XV3dIcwjLM4sADWX00JaP/LXLS 1MgI5a5qZvxE/yh0eTQ2K1r5uT8ECcfF6QUsQZoyIZIqjVly0Dcy3udpbiD0Z2eg5R+aTlr741nq7 Xku0rdoLOrVXGMr7M4dyqQ==; In-Reply-To: (message from arthur miller on Sat, 9 Nov 2024 20:29:29 +0000) 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:325366 Archived-At: > From: arthur miller > CC: "emacs-devel@gnu.org" > Date: Sat, 9 Nov 2024 20:29:29 +0000 > > In other words, there might be variables live outisde of > the loop-scope we wish to access in the loop, and that is > what Yuri's example shows. However, i,j are not re-initiated > on each iteration, but remembers their value. The effecto of > while-let in current implementation is that i,j are re-initiated > in each iteration, not re-evaluated, if that makes it clear. > > I am not sure how to illustrate in a better way. The net effect is > that lexical variables declared in while-let loop are "read-only". > > They are not, but since they are re-iniated, it is pointless to > write to them. You can write to them indirectly, if the evaluation is properly written. If the evaluation is just assigning a fixed value to a variable, then yes, writing to that variable in the body is pointless; but then so is the use of while-let, IMO. Even in your for-loop example from C, the CONDITION part of the loop is re-evaluated on each iteration, and if you assign some fixed value to the loop control variables there, your loop might become an infloop, regardless of what you do in the body with those variables. That's basically what the example of while-let you show at the beginning of this discussion did. > Of course, all loop predicates should be evaled on each iteration, > but not re-iniated on each iteration. If that makes sense. Sorry, > I am not very good at writing. If while-let doesn't seem to do the job in some code of yours, then don't use it there. Use something else. AFAIU, while-let was introduced for those cases where its use makes sense and does the job cleaner and clearer than the alternatives. It could be abused, of course, but that's not necessarily its fault, is it? Anyway, to get this long discussion back on track: is there a need to clarify something in the documentation of while-let? if so, what?