From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59140: 29.0.50; iter-yield from lambda Date: Fri, 15 Sep 2023 18:18:56 -0400 Message-ID: References: <87sfissyz3.fsf@web.de> <87v8cb9pns.fsf@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26505"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Michael Heerdegen , 59140@debbugs.gnu.org, okamsn@protonmail.com To: Max Brieiev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 16 00:20:11 2023 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 1qhHAY-0006j0-HL for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Sep 2023 00:20:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhHAL-00030Y-6o; Fri, 15 Sep 2023 18:19:57 -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 1qhHAJ-00030C-CG for bug-gnu-emacs@gnu.org; Fri, 15 Sep 2023 18:19:55 -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 1qhHAJ-0005oM-44 for bug-gnu-emacs@gnu.org; Fri, 15 Sep 2023 18:19:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qhHAP-0003pW-LC for bug-gnu-emacs@gnu.org; Fri, 15 Sep 2023 18:20:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Sep 2023 22:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59140 X-GNU-PR-Package: emacs Original-Received: via spool by 59140-submit@debbugs.gnu.org id=B59140.169481635414650 (code B ref 59140); Fri, 15 Sep 2023 22:20:01 +0000 Original-Received: (at 59140) by debbugs.gnu.org; 15 Sep 2023 22:19:14 +0000 Original-Received: from localhost ([127.0.0.1]:45037 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qhH9d-0003oE-SW for submit@debbugs.gnu.org; Fri, 15 Sep 2023 18:19:14 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:55884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qhH9c-0003o1-4h for 59140@debbugs.gnu.org; Fri, 15 Sep 2023 18:19:13 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A0906805A9; Fri, 15 Sep 2023 18:18:59 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1694816338; bh=yfmM1dmNlHY4ISl46/2g9k7jBooA11RpjSW2tOjC7CA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=RtIaRyk1a5T6NJelFedz9ohOnpLVbpi47wsEa/ehBbZW5QrZm81CxMX4LsENVziHS 3Fq84UF8/tGUMUWebPmfbDsRmOvMLalpeOPm8no18GUgGqgP9YnzcXc7SM3GhPccJW u4yYaA6PFZQGPgtU7PpBofhq/nKw1ycxdIBR+MbMT/rr7bW2x8lEMmhD4F5Hfkc7z0 C43sY8GRZ2IrE0q05NEOTHNee8NEcfWw/m2HQorZngesuyyZGQM+zVtHn7dSdLsvOD 7KF1E9DYPboEICDn0FfrEJclRrJUQGNmffQCSi5C9LTdPO4jF8MkapZUNfk371PCVk SHqBPwkgMZfEg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 51C4C803B1; Fri, 15 Sep 2023 18:18:58 -0400 (EDT) Original-Received: from pastel (unknown [104.247.237.102]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E0FC5120009; Fri, 15 Sep 2023 18:18:57 -0400 (EDT) In-Reply-To: <87v8cb9pns.fsf@gmail.com> (Max Brieiev's message of "Fri, 15 Sep 2023 22:56:07 +0300") 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:270565 Archived-At: >>> IIRC, one of the main limitations of `generator.el` is that it doesn't >>> handle `lambda` (and neither should you use `#'iter-yield`, IIRC). >>> >>> I don't really know how to go about fixing it. >>> >>> A good first step would be to make sure it emits an error (or a warning) >>> when you use `#'iter-yield` or when you call `#'iter-yield` from with >>> a lambda expression. > > Is this unfixable in principle or the fix is just hard (non-obvious)? To do its job, `generator.el` performs a kind of CPS (continuation passing style) conversion. Such a conversion can be made to handle "the whole language" fairly easily, but at the cost of being unable to interact seamlessly with code which has not gone through the same transformation. So, yes, in principle it can be fixed *if* we make every single chunk of ELisp code go through that transformation (plus adjust accordingly all the primitives implemented in C). Since that's not an option, `generator.el` uses a "local CPS conversion" but these can't handle higher-order functions in general because they need to be able to determine easily what is "local" and first-class functions give you way to much power to play with the control flow. So in practice it's not fixable. > If iter-yield is lexically scoped within lambda expression, then could > the lambda possibly be replaced with the iter-lambda? Yes, if you can determine *all* the places from where this lambda can be called and if you can then also change all the other lambdas that can be called from one of those places, plus all the places where those other lambdas can be called, plus all the other lambdas that can be called from those other places, etc.... :-( Stefan