all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 23430@debbugs.gnu.org, Stefan Kangas <stefan@marxist.se>
Subject: bug#23430: 25.0.93; iter-defun does not support special form save-current-buffer
Date: Sun, 16 Aug 2020 15:33:38 +0200	[thread overview]
Message-ID: <87tux2btql.fsf@web.de> (raw)
In-Reply-To: <d7ae1f11-7c1e-24f8-79d4-dab73a17a64f@yandex.ru> (Dmitry Gutov's message of "Wed, 12 Aug 2020 13:06:33 +0300")

Dmitry Gutov <dgutov@yandex.ru> 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.

AFAIK handling asynchronous process output is not a good task for them.

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

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.

Just extrapolating my university knowledge however...


Michael.





  reply	other threads:[~2020-08-16 13:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-03  1:31 bug#23430: 25.0.93; iter-defun does not support special form save-current-buffer Dmitry Gutov
2016-05-05 22:46 ` Dmitry Gutov
2016-05-06 23:25   ` Michael Heerdegen
2016-05-06 23:30     ` Dmitry Gutov
2020-08-12  2:41   ` Stefan Kangas
2020-08-12 10:06     ` Dmitry Gutov
2020-08-16 13:33       ` Michael Heerdegen [this message]
2020-08-22  0:18         ` Dmitry Gutov
2020-08-18 12:08       ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tux2btql.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=23430@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=stefan@marxist.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.