From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: arthur miller Newsgroups: gmane.emacs.devel Subject: Sv: Is this a bug in while-let or do I missunderstand it? Date: Sat, 9 Nov 2024 13:38:24 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="_000_DU2PR02MB10109F4094C90A796CD77B809965E2DU2PR02MB10109eu_" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18704"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "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 15:56:40 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 1t9mtE-0004jW-9D for ged-emacs-devel@m.gmane-mx.org; Sat, 09 Nov 2024 15:56:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9msP-00007X-2k; Sat, 09 Nov 2024 09:55:49 -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 1t9lfa-00042A-4n for emacs-devel@gnu.org; Sat, 09 Nov 2024 08:38:30 -0500 Original-Received: from mail-db8eur05olkn2067.outbound.protection.outlook.com ([40.92.89.67] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9lfX-0007Cq-V0 for emacs-devel@gnu.org; Sat, 09 Nov 2024 08:38:29 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZZY+JLXVun4JSTleVfYUoF1xXrHGGSdkR+Ql82YSl1tZOT41k7bOdYchlQGF/8Nw1aABpUIRQGaz+osdOMGZmx7kGDBCJUeSHO/lEs7UiOjCAkz+RLyLGiPdfRLtq+zERLdv/2BkuypcSveEMeeD/sBBkJPXlmKLKN/ir/778PMh6/+IIPKl/xXz5VZtHMvDsdUizxdvrUlw6MfD5XxKdwdcM9VSdE1cQbC7hEzJgVvjFtVemIhfofA4CAOkif9T7YC63TmMZgH3pINiY/s/hLHVVxPytTabbANBjXJK6lYM7SQznmI/4jNTFMfFYhlxblv6h2ejQ/JZYhAcGGyskw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ExmzJJsvkCpK8GNbhuFoLAylHB1gpGQ2/uY8ofW+41M=; b=YhsWQBDepc4lR7+6XUJU7MoImNOF/lMcij2JQdJjn4VaqYNrt6veYVkeMMWdioLre0fbrCLSp2U3gL7+WgWU/0SMBM2F+MX526qI16X+3zj+Nq8tNlMsRaVxWgQsKJI5yQIROjcLjFHB3VLNvt3ONTn3DsTT3C8HFEGiwu9YtHzni36ADM1wVj31Zs32CoPnoUwFmmTGzQZj9Oz9BI7UWBnpIYpp+0LWutsKfmPHOj1auAprlVI2/RqJvL/TLjpRWvbwBkMZdRcmk6saTeiEYLjhinV3mdalwZt1Vj6omIZEcakfZhm+Qcr+++nWUj3arFwVk8OwQPtrcxVYnVlztw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ExmzJJsvkCpK8GNbhuFoLAylHB1gpGQ2/uY8ofW+41M=; b=Q3WKOCZk7ToWfDAhZ3cFXLQrK6ilcTFZdSLmlfM6advepRp/y74pWLjLI/bU4cmewGkoPEkbs44DZn9lbbE8/iYu4axfwyLC+H7ptn+gwAkzt3GoLuuRhDMT3CF1+9PmLxn3JOn4WM7p0qf7nKLjYW7HcRb/3uTOexinVv5K4XYTAGvP5H2Ps86O1Bm9/isujakwzF367yFPqNTHX1UV6ScJ1iEwZLx1xxH6dg+Pc8NjfZZYBOFV33DxIPHQPi6VEcaNJ2YAPavrmQaFvfdNKQ3FQWy5U5Kr/LGc4kKRzAZLd8vXOIsqx3JbHG3E2YAoN1exK3Qgw9SaSUYt40GXsw== Original-Received: from DU2PR02MB10109.eurprd02.prod.outlook.com (2603:10a6:10:497::14) by DBAPR02MB6053.eurprd02.prod.outlook.com (2603:10a6:10:181::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.26; Sat, 9 Nov 2024 13:38:24 +0000 Original-Received: from DU2PR02MB10109.eurprd02.prod.outlook.com ([fe80::f3c9:d4cb:290:d487]) by DU2PR02MB10109.eurprd02.prod.outlook.com ([fe80::f3c9:d4cb:290:d487%4]) with mapi id 15.20.8137.022; Sat, 9 Nov 2024 13:38:24 +0000 Thread-Topic: Is this a bug in while-let or do I missunderstand it? Thread-Index: AQHbMfbIoZNom93mHkmQsSTvSCnRb7Kur/AAgAA0XUGAAAq2gIAAAU7J In-Reply-To: Accept-Language: sv-SE, en-US Content-Language: sv-SE x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DU2PR02MB10109:EE_|DBAPR02MB6053:EE_ x-ms-office365-filtering-correlation-id: 46b0347f-b0a9-4d06-fb72-08dd00c3c8f7 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|7092599003|15030799003|8060799006|19110799003|15080799006|8062599003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: =?Windows-1252?Q?lC9sffiEHcIcbtwciHTs4wya+lNzPa7toWNJo5hbX5BJic0IPknGPTqt?= =?Windows-1252?Q?IpnqjfTyDWcJc+pwBQQCFGRS1MtH2SFBzc0pq9duu3YVmb6aRvkWQCEb?= =?Windows-1252?Q?oO5PM7/eYW1bwnKoH+rP3FHcuxgqSGTLzdXr8xL5ISuZ5rf6j8xBggf6?= =?Windows-1252?Q?f2XyqE8kG12qlzvc9fgRWkUpw0w56h3CvTiiG/KJAA8XkYBF/yLqe0lI?= =?Windows-1252?Q?+uIoDc9loLnfYJkmVEN4WaxGL5OOp13cwNATiEZPscc5Yl4FLCtAkUe6?= =?Windows-1252?Q?fUMDZV9xjiNrq3WF5NxYA06U/PXtWVxFY0KTZYLZfjRO0F+UOl/GDN4C?= =?Windows-1252?Q?12+qLKM4uy6KD3ikr3ZIejv7TpcX1yUpEidxUygkQZl5ae0oX/uYfM9c?= =?Windows-1252?Q?PIQ2VBytx/tTCsGOaRZ//w5YzXE9JBs5T8GxhxubAcon+6O4i/pxJehL?= =?Windows-1252?Q?LDR+h2LgljATDMxHAKGKmDOTnueK6927lmYHQQ6yCDQTU3FJUADRdC8t?= =?Windows-1252?Q?2/A184AeMf/ETgbGO0DutWqE8CJ6T9QQkIIsQoSjR25EQbd2195WekKz?= =?Windows-1252?Q?KM7gfAJA2Naj5PeGfEkl+aYurlrxQA4rEcpDfNdRIqVmt3wGPwABnrbi?= =?Windows-1252?Q?f x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?Windows-1252?Q?gyrD1rUvqylMSBO8vYN8OfJOhYcVKnmoGztSOe80il5Qd55+dKbkvaca?= =?Windows-1252?Q?/alygBkMSrN2AcydmbzrBfHHN+awwNegFWxD8AJZuSbeD3TdDmfO5292?= =?Windows-1252?Q?Ct2PfopXRCXleVfu1iGsIe0jRcqLZxaD9LEqDfc0JjU64H/LavHJL5J9?= =?Windows-1252?Q?N/8nn6Q/T4hM2Z9I594XajczHqT1klvq5VheW7m14Y2tPKzkrKBWsY5G?= =?Windows-1252?Q?Pkx8K0WyUFiftnHJBbDlpKi03WRG8tm9vdLB0LMOpRLhidJDi26f/oXh?= =?Windows-1252?Q?83tiaLh2hD+ZTnfWQ7JIJWzYu8DlvzWVcfRVQNWAEhmHeH/QLgxLsX3d?= =?Windows-1252?Q?EVWQawhQsKiXHrbAQFjDyLzNLZuyfH4a5uMWx1JbugZigIq1FSBlvfu5?= =?Windows-1252?Q?eUTbI0xtFyOSjlICX0tdAXPwDc2cXMYZr0x1H4aGNjCFnzei5DOaCuot?= =?Windows-1252?Q?7utyKQD+jrPk0kPigoksSFgVxZXYuLq1X0t2eSJ5of16ijxrRCwCpCDu?= =?Windows-1252?Q?NRTTX56b1Wph7CRM+2cK/4pHU7urK1blEPej0XBx6jwzbYWtrRYdMXNX?= =?Windows-1252?Q?V9E4R+11DO/af0xocu3bhYCM6WZ6cyrviKYk7NF/wjEiWp9ceqbAyCek?= =?Windows-1252? X-OriginatorOrg: sct-15-20-7828-19-msonline-outlook-12d23.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DU2PR02MB10109.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 46b0347f-b0a9-4d06-fb72-08dd00c3c8f7 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Nov 2024 13:38:24.6676 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR02MB6053 Received-SPF: pass client-ip=40.92.89.67; envelope-from=arthur.miller@live.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 09 Nov 2024 09:55:47 -0500 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:325338 Archived-At: --_000_DU2PR02MB10109F4094C90A796CD77B809965E2DU2PR02MB10109eu_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable >> >> (progn >> >> (while-let ((run t)) >> >> (message "Running") >> >> (setf run nil)) >> >> (message "out of loop")) >> >> >> >> It ends in infinite recursion. setf/setq have no effect on the lexica= l variable. >> > >> >Probably not infinite recursion but infinite loop. >> > >> >Why would you expect anything else? =91while-let=92 is documented as: >> > >> > Bind variables according to SPEC and conditionally evaluate BODY. >> >> What should I expect? >> >> It does not says *read-only bindings*, it says bindings. Is it >> unreasonable to store a value in an established lexical binding? > >I expect the binding is writable *but* it gets re-assigned on each iterati= on. Yes. >> That is what I expect while-let to be equivalent to. > >This is what I expect: > > (progn > (let ((run)) > (while (setf run t) > (message "running") > (setf run nil) ; useless because =91run=92 will be >reassigned right next > ) > (message "not running") ; unreachable > ) > Mnjah; more like this: (catch 'done (while t (let* ((run nil)) (if run (do-body) (throw 'done nil))))) I have already posted the macro expansions in respone to Phillip. It is quite clear what is going on. I think it is a bug, or at least very unintuitive behaviour. But the worst, we can see that the claimed optimizaiton does not take place at all: (pp (macroexpand-all '(while-let ((run t) (x 'expensive) (y 'more-expensive) (z 'the-most-expensive)) (message "running") (setf run nil)))) (catch 'done1522 (while t (let* ((run (and t t)) (x (and run 'expensive)) (y (and x 'more-expensive= )) (z (and y 'the-most-expensive))) (if z (progn (message "running") (setq run nil)) (throw 'done1522 nil= ))))) Which makes wonder if the convoluted code in subr.el is worth compared to t= he naive implementation I posted. Perhaps someone can pull off the optimizatio= n with some clever macro, I don't know. I think it was enough from me as an outsider to point out the possible bug.= Whether people here wants to poop on it, or acknowledge and fix the bug is not up = to me. In other words, I think I am done here. /best regards ________________________________ Fr=E5n: Yuri Khan Skickat: den 9 november 2024 14:15 Till: arthur miller Kopia: emacs-devel@gnu.org =C4mne: Re: Is this a bug in while-let or do I missunderstand it? On Sat, 9 Nov 2024 at 20:03, arthur miller wrote: > > >> (progn > >> (while-let ((run t)) > >> (message "Running") > >> (setf run nil)) > >> (message "out of loop")) > >> > >> It ends in infinite recursion. setf/setq have no effect on the lexical= variable. > > > >Probably not infinite recursion but infinite loop. > > > >Why would you expect anything else? =91while-let=92 is documented as: > > > > Bind variables according to SPEC and conditionally evaluate BODY. > > What should I expect? > > It does not says *read-only bindings*, it says bindings. Is it > unreasonable to store a value in an established lexical binding? I expect the binding is writable *but* it gets re-assigned on each iteratio= n. > (progn > (let ((run t)) > (while run > (message "running") > (setf run nil)) > (message "not running"))) > > That is what I expect while-let to be equivalent to. This is what I expect: (progn (let ((run)) (while (setf run t) (message "running") (setf run nil) ; useless because =91run=92 will be reassigned right next ) (message "not running") ; unreachable ) --_000_DU2PR02MB10109F4094C90A796CD77B809965E2DU2PR02MB10109eu_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
>> >> (progn
>> >>   (while-let ((run t))
>> >>     (message "Running")
>> >>     (setf run nil))
>> >>   (message "out of loop"))
>> >>
>> >> It ends in infinite recursion. setf/setq have no effect o= n the lexical variable.
>> >
>> >Probably not infinite recursion but infinite loop.
>> >
>> >Why would you expect anything else? =91while-let=92 is documen= ted as:
>> >
>> >    Bind variables according to SPEC and conditional= ly evaluate BODY.
>>
>> What should I expect?
>>
>> It does not says *read-only bindings*, it says bindings. Is it
>> unreasonable to store a value in an established lexical binding?
>
>I expect the binding is writable *but* it gets re-assigned on each iter= ation.

Yes.

>> That is what I expect while-let to be equivalent to.
>
>This is what I expect:
>
>    (progn
>      (let ((run))
>        (while (setf run t)
>          (message "running")
>          (setf run nil)       = ; useless because =91run=92 will be
>reassigned right next
>        )
>      (message "not running")  ; unreacha= ble
>    )
>

Mnjah; more like this:

(catch 'done
  (while t
    (let* ((run nil))
      (if run
          (do-body)
          (throw 'done nil)))))

I have already posted the macro expansions in respone to Phillip.
It is quite clear what is going on. I think it is a bug, or at
least very unintuitive behaviour. But the worst, we can see that the
claimed optimizaiton does not take place at all:

(pp (macroexpand-all
     '(while-let ((run t)
                  (x 'expensiv= e)
                  (y 'more-exp= ensive)
                  (z 'the-most= -expensive))
        (message "running")
        (setf run nil))))

(catch 'done1522
  (while t
    (let*
        ((run (and t t)) (x (and run 'expensive)) (y (a= nd x 'more-expensive))
         (z (and y 'the-most-expensive)))
      (if z (progn (message "running") (setq run n= il)) (throw 'done1522 nil)))))

Which makes wonder if the convoluted code in subr.el is worth compared to t= he
naive implementation I posted. Perhaps someone can pull off the optimizatio= n with
 some clever macro, I don't know. 

I think it was enough from me as an outsider to point out the possible bug.= Whether
 people here wants to poop on it, or acknowledge and fix the bug is no= t up to me. 

In other words, I think I am done here.

/best regards

Fr=E5n: Yuri Khan <yuri.= v.khan@gmail.com>
Skickat: den 9 november 2024 14:15
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
=C4mne: Re: Is this a bug in while-let or do I missunderstand it?
 
On Sat, 9 Nov 2024 at 20:03, arthur miller <art= hur.miller@live.com> wrote:
>
> >> (progn
> >>   (while-let ((run t))
> >>     (message "Running")
> >>     (setf run nil))
> >>   (message "out of loop"))
> >>
> >> It ends in infinite recursion. setf/setq have no effect on th= e lexical variable.
> >
> >Probably not infinite recursion but infinite loop.
> >
> >Why would you expect anything else? =91while-let=92 is documented = as:
> >
> >    Bind variables according to SPEC and conditiona= lly evaluate BODY.
>
> What should I expect?
>
> It does not says *read-only bindings*, it says bindings. Is it
> unreasonable to store a value in an established lexical binding?

I expect the binding is writable *but* it gets re-assigned on each iteratio= n.

> (progn
>   (let ((run t))
>     (while run
>       (message "running")
>       (setf run nil))
>     (message "not running")))
>
> That is what I expect while-let to be equivalent to.

This is what I expect:

    (progn
      (let ((run))
        (while (setf run t)
          (message "runni= ng")
          (setf run nil) =       ; useless because =91run=92 will be
reassigned right next
        )
      (message "not running")  ; un= reachable
    )
--_000_DU2PR02MB10109F4094C90A796CD77B809965E2DU2PR02MB10109eu_--