From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#23430: 25.0.93; iter-defun does not support special form save-current-buffer Date: Sat, 22 Aug 2020 03:18:08 +0300 Message-ID: <87fd8e2a-6566-b451-48af-e1966ce1f8eb@yandex.ru> References: <86k2jc2ahf.fsf@yandex.ru> <87tux2btql.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24051"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Cc: 23430@debbugs.gnu.org, Stefan Kangas To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 22 02:19:10 2020 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 1k9HFW-00069j-Fu for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Aug 2020 02:19:10 +0200 Original-Received: from localhost ([::1]:37370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9HFV-00037y-Fe for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 21 Aug 2020 20:19:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9HFO-00037a-G0 for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2020 20:19:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36979) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k9HFO-0006dJ-79 for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2020 20:19:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k9HFO-0002xJ-3Q for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2020 20:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Aug 2020 00:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23430 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 23430-submit@debbugs.gnu.org id=B23430.159805549811312 (code B ref 23430); Sat, 22 Aug 2020 00:19:02 +0000 Original-Received: (at 23430) by debbugs.gnu.org; 22 Aug 2020 00:18:18 +0000 Original-Received: from localhost ([127.0.0.1]:48525 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k9HEg-0002wO-J4 for submit@debbugs.gnu.org; Fri, 21 Aug 2020 20:18:18 -0400 Original-Received: from mail-lf1-f53.google.com ([209.85.167.53]:45339) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k9HEe-0002wA-EK for 23430@debbugs.gnu.org; Fri, 21 Aug 2020 20:18:17 -0400 Original-Received: by mail-lf1-f53.google.com with SMTP id b30so1727532lfj.12 for <23430@debbugs.gnu.org>; Fri, 21 Aug 2020 17:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=rL98Eb/QSsDe+qxYbd/KW/o1cfeLryHxgYA4Lucpebs=; b=SU+/kVQxlVWK6TrjGl2VtLaVrP6tes5uX0ewGuShkzSXP7CQDElyTydqxXK6B6Fvyj z+q39Otjs85h+7d986KDtNHL4MPSH/1jjGkAiv9UDKkdhTTLlSSzaY8tjUH0F44qyh8h s7Jl59w1bssOHTPb8AvE/2RR5ri930MEyGZZvXHxP0ywtgDDo14pGstER4lmq8H3nhQa wZBMgkMg62nZ8dc/li2Dcz29vMP5g2dBq21bDlIZD6u5m3FyLpD2a0FwLcgOPsuSr4qw 1cCpfx7OP2sbjrTYbkxVydnpc+RxhkX5muJbC+6dezQNG9rNSHyxfHOlA9soG8ivY14E bIKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rL98Eb/QSsDe+qxYbd/KW/o1cfeLryHxgYA4Lucpebs=; b=MhO5l33ZarIjPIuRhzlJUPaaFv14Us9l5GeCKL3FMUF79IhOfSsQ+yu5BtGi5GnLiL GgmJTd0CkEeZa1NK9xy8Y8k7PKIqN9Rs5YQHTkAi0YY7d2lsEipDSIHcapDI17aiRP5/ 8YcM7n1fvU9F8p2358fZOfIYnFxMxF4vmGZptFwrWLvccSVNuK/VdZhfOc1BwA/fyD20 pIqqCbuN3jil0qYcBEaYb+MfcPG00P3TpygylWg/uZrncZOww3h+ackCudrxMQG5D6cG q8F/4fErf5ps5ESd8gxzHCp8zqMP5RyJlGp4lTFxiSg84e+GZn7M6lQoXzdYbeUwU7pZ t+nw== X-Gm-Message-State: AOAM531B0lB6nPaPfNiHYaWgLRlmICoUvBLSFi+ifNRIlP2UGbYAdMWL S7SLtZOR9vk5QkEfPeQk2m4= X-Google-Smtp-Source: ABdhPJwBDSJIYhzf027LWJCklCTu1zVA4ni/OwC054NT4BKMY3gYCMdiFWHTbNKROcBn+nKeLgoBaw== X-Received: by 2002:a19:f808:: with SMTP id a8mr2474871lff.62.1598055490403; Fri, 21 Aug 2020 17:18:10 -0700 (PDT) Original-Received: from [192.168.0.104] ([94.229.108.16]) by smtp.googlemail.com with ESMTPSA id u10sm678091lju.113.2020.08.21.17.18.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Aug 2020 17:18:09 -0700 (PDT) In-Reply-To: <87tux2btql.fsf@web.de> Content-Language: en-US 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" Xref: news.gmane.io gmane.emacs.bugs:185913 Archived-At: On 16.08.2020 16:33, Michael Heerdegen wrote: > Dmitry Gutov writes: > >> Before we close this, I'd like to hear from somebody who understands >> what generator.el is actually for. > > I think it's just a straightforward implementation of generators as > described here: > > https://en.wikipedia.org/wiki/Generator_%28computer_programming%29 > > I learned about them in university, and have used them once in a while. Right. I was really wondering, though, whether we can/should use them more often. > AFAIK handling asynchronous process output is not a good task for them. Perhaps if we also used a separate thread for waiting for the output to come... > I think: The problem of the concept of generators in an editor is that > generators are good for saving the state of a computation, but Emacs as > an editor has a lot of "environment" state (current buffer, value of > point, ...), and when the computation represented by the generator > messes with this state (or has side effects), the concept doesn't fit > that well. > > When working with streams, I make the handling of the according part of > the environment explicit saving it in variables (iterators are closures) > and "yield" outside of any xxx-recursion, in your introductory example, > that would look like this: > > #+begin_src emacs-lisp > (require 'generator) > > (iter-defun my-search (str buf) > (with-current-buffer buf > (goto-char (point-min))) > (let ((pos (point)) > (yield nil) > (done nil)) > (while (not done) > (when yield > (iter-yield yield) > (setq yield nil)) > (with-current-buffer buf > (goto-char pos) > (if (search-forward str) > (setq yield (match-beginning 0) > pos (point)) > (setq done 0)))))) > #+end_src Thanks. I think this is fairly close to the approach I showed in the patch. Problem is, it's no shorter than an implementation one can write using plain functions. Longer, usually. > I guess it would be nice if that could work implicitly in some way, but > that would probably require the introduction of new special forms > adapted to the situation, like `iterator-save-buffer-and-point' or so. Perhaps.