From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#71120: 29.3; buglet in cl-loop Date: Wed, 29 May 2024 20:47:56 +0000 Message-ID: <87cyp4wdj7.fsf@posteo.net> References: <23fd70f8-6e01-45d7-b9f9-d81d53c95ffd@lmf.cnrs.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32356"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71120@debbugs.gnu.org, Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Stefan Monnier To: Philippe Schnoebelen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 29 22:49:03 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1sCQEJ-0008EV-7s for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 May 2024 22:49:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCQEB-0004ur-0j; Wed, 29 May 2024 16:48:55 -0400 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 1sCQE8-0004ug-FM for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 16:48:52 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCQE8-0001KT-1V for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 16:48:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sCQEH-0005dx-Q1 for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 16:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 May 2024 20:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71120 X-GNU-PR-Package: emacs Original-Received: via spool by 71120-submit@debbugs.gnu.org id=B71120.171701570421580 (code B ref 71120); Wed, 29 May 2024 20:49:01 +0000 Original-Received: (at 71120) by debbugs.gnu.org; 29 May 2024 20:48:24 +0000 Original-Received: from localhost ([127.0.0.1]:53714 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCQDf-0005bx-Kz for submit@debbugs.gnu.org; Wed, 29 May 2024 16:48:24 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:36539) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCQDd-0005bZ-RN for 71120@debbugs.gnu.org; Wed, 29 May 2024 16:48:23 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 5137724002D for <71120@debbugs.gnu.org>; Wed, 29 May 2024 22:48:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1717015685; bh=ADbFYwwf+mszdxEwcXuw8qaLBTtBU7Mz/AwLY+yO1ek=; h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding:From; b=d9nVWilfPaQ2nqhvrmN2h86X7QSuiO8D41Hf4vFtAN+q9W4J2xJb455+KyIrX4RP1 3ns9g7qmvaMZjKN+yUXT7z9MtJBzq0B34rOrWJf43WIEk1gaQL7jN7uWpVRoEvwj+o ozWqRszHlm6OsNvJH96i/NSl8ic3VLYJlb96Ooq2GEYKjZltNlJ1FXc5IpqtonprGp PW1Nt+cohbPydYHwky62zP5uFrdwCc0PsKfNxfmFHzvryssfqNpzRRHzmI/1DQ3P1+ nOQJgXLsvANOpPP7cxIXSSVuWFNKIzOQHtmxrByQ+EZDDt7Xitl+stQ4dJF34fPhwm vKD7pFTCedKMw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VqM0G0RwTz9rxK; Wed, 29 May 2024 22:47:57 +0200 (CEST) In-Reply-To: <23fd70f8-6e01-45d7-b9f9-d81d53c95ffd@lmf.cnrs.fr> (Philippe Schnoebelen's message of "Wed, 22 May 2024 10:43:36 +0200") OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286180 Archived-At: Philippe Schnoebelen writes: > When I need a list of 100 random dice throws I write > > (cl-loop for i from 1 to 100 collect (random 6)) > > It compiles just fine. > > If instead I use > > (cl-loop for _i from 1 to 100 collect (random 6)) > > then I get a compilation warning: > > foo.el:1:18: Warning: variable =E2=80=98_i=E2=80=99 not left unused > > It should be the other way around. The issue here is that the warning describes an issue in the output, in the latter case (let* ((_i 1) (--cl-var-- nil)) (while (<=3D _i 100) (setq --cl-var-- (cons (random 6) --cl-var--)) (setq _i (+ _i 1))) (nreverse --cl-var--)) As you see, _i is both evaluated in (+ _i 1) and updated. Here you have a minimal working example of the warning: (byte-compile (lambda () (let ((_x 3)) _x))) ;; Warning: variable =E2=80=98_x=E2=80=99 not left unused My guess is that fixing this would require cl-loop to notice that the counter is prefixed with a "_" and then use some other variable, but that might lead to issues with existing code. Perhaps this transformation might be safe in that case: (let* (( 1) (--cl-var-- nil)) (while (<=3D 100) (let ((_i )) (setq --cl-var-- (cons (random 6) --cl-var--)) (setq (+ 1)))) (nreverse --cl-var--)) I have added Mattias and Stefan to the CCs, as they'll probably have more qualified comments to add. > > The variable 'i' is unused in the first form and that deserves a > warning at compile time. Otherwise the compiler will not help me catch > the typo in > > (cl-loop for i from 0 to 10 do > (cl-loop for j from 0 to 10 do > (foo j j))) ;; <<<=3D=3D=3D typo, I meant (foo i j) > > > --ph.schnoebelen, happy and thankful GNU Emacs user since 1983 (Thanks > to all involved!!) > > > > > --=20 Philip Kaludercic on peregrine