From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#71120: 29.3; buglet in cl-loop Date: Wed, 29 May 2024 17:33:49 -0400 Message-ID: References: <23fd70f8-6e01-45d7-b9f9-d81d53c95ffd@lmf.cnrs.fr> <87cyp4wdj7.fsf@posteo.net> 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="22797"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 71120@debbugs.gnu.org, Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Stefan Monnier , Philippe Schnoebelen To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 29 23:35:16 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 1sCQx1-0005a5-EJ for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 May 2024 23:35:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCQwg-0007vS-Tz; Wed, 29 May 2024 17:34:54 -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 1sCQwe-0007uu-SV for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 17:34: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 1sCQwe-0000bz-K7 for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 17:34:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sCQwo-0007vr-GI for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 17:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 May 2024 21:35:02 +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.171701845030248 (code B ref 71120); Wed, 29 May 2024 21:35:02 +0000 Original-Received: (at 71120) by debbugs.gnu.org; 29 May 2024 21:34:10 +0000 Original-Received: from localhost ([127.0.0.1]:55715 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCQvx-0007ro-VF for submit@debbugs.gnu.org; Wed, 29 May 2024 17:34:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34354) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCQvw-0007rB-8Y for 71120@debbugs.gnu.org; Wed, 29 May 2024 17:34:09 -0400 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 1sCQve-0000Wv-Ec; Wed, 29 May 2024 17:33:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=DKDHKbWHQAcfP0rzw9QvrNctHARnk8k/X5EQ10nIZZA=; b=F5rYl3rFwOJkgDN4Fycz JPzvtFRM7btD2ibE8abLUPFnePAhkWKbhjf0ku5gBIIa9mmlNU5sNsWK5/IZZpPLd7qHZYMAAcXx+ EtJC78XVKHRNJww/jBMg3bSU4ddsRtrR2vBSqwyNxktvvDlLB4lbNkAJ3ZspaF7W5DjMb09+ueuK6 13dqyiUADsWBfP//qlYPy/vkJnxmnlR78x2jckYKU6n3H9rlCT5Re7BT81YMGYZawIGFdC2xB0VBf lEDt9yJ2195Xma0fE7Ac/lrWL2KQ7rZAVcWa+/PoLJglKHanNiY9ooYSZVqYTIUAPcnE2qaKduO3X VPOYT2oahn+27w==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1sCQvd-00075P-Vr; Wed, 29 May 2024 17:33:50 -0400 In-Reply-To: <87cyp4wdj7.fsf@posteo.net> (Philip Kaludercic's message of "Wed, 29 May 2024 20:47:56 +0000") 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:286185 Archived-At: Philip Kaludercic writes: > 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. This is the same transformation that came to my mind reading the orginal report, I think it should be safe. BTW Philippe, you can workaround the bug with: (cl-loop repeat 100 collect (random 6)) Bests Andrea