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:49:10 -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="15776"; 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:50:07 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 1sCRBO-0003xV-S1 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 May 2024 23:50:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCRBB-0004HC-4Z; Wed, 29 May 2024 17:49:53 -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 1sCRB9-0004Gg-Pd for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 17:49:51 -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 1sCRB9-0003Lg-Ha for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 17:49:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sCRBJ-0000Cw-JG for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 17:50:01 -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:50: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.1717019371724 (code B ref 71120); Wed, 29 May 2024 21:50:01 +0000 Original-Received: (at 71120) by debbugs.gnu.org; 29 May 2024 21:49:31 +0000 Original-Received: from localhost ([127.0.0.1]:56449 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCRAo-0000Bb-In for submit@debbugs.gnu.org; Wed, 29 May 2024 17:49:30 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50828) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCRAm-0000BG-57 for 71120@debbugs.gnu.org; Wed, 29 May 2024 17:49:29 -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 1sCRAV-0003HO-4x; Wed, 29 May 2024 17:49:11 -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=pDJpNi2hb+n+FtmCJbRKndmHdQ8plg6bXcNsa8ufz04=; b=Ad6uqZo+0ntn1XmWe3w0 vC0jEYtSqwQRMqGHtNRo8xH/uWPe6rCtJYaHn5T34SiODbyyChhuwh8DLVGf2pXrdyDPPa9JtGsIn IXHj+H6pHaCqxDCBwx2aUygoS2d39udcS9n+zpN8/oABGxmR1sdbZc5YVs7fevdxlaW97uBkLPaoo Jc/fw/yG7EhejAlQYNIFH+LKYSphm+y0fWPhTPurfCHLa8XJy4SBuVUXyh7TDnBezSzlvl9PCeinD s6QXrLqQ2EJRWHI0pnA/uwN2FNt4r6ruwWB6TQTQ3bve/gtmUh4GhtG67Kpbpuq95DVCyDd3Qx8kc 9e3GnZaUHGeOLg==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1sCRAU-0007ow-FA; Wed, 29 May 2024 17:49:10 -0400 In-Reply-To: (Andrea Corallo's message of "Wed, 29 May 2024 17:33:49 -0400") 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:286187 Archived-At: Andrea Corallo writes: > 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. As a datapoint, SBCL does expands this with inside a (declare (ignore i)) Unfortuantelly we don't support it :/ and our 'ignore' doesn't work here as goes in the opposite direction :( Andrea