unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 26073@debbugs.gnu.org
Subject: bug#26073: workaround
Date: Mon, 20 Mar 2017 15:20:58 +0100	[thread overview]
Message-ID: <CAG7BpareaWF2pC=inF2cpx-bzo50EQf5gxJaUU3q18UFORTCKg@mail.gmail.com> (raw)
In-Reply-To: <jwv37e8axu7.fsf-monnier+Inbox@gnu.org>

> Could you give me some concrete (but simple) example?

Basically, when you define a generator function

    (iter-defun foo ()
      (let ((x (bar 1)))
        (iter-yield x)
        (iter-yield (+ x (bar 2)))))

the resulting iterator must somehow preserve value of `x' after
the first yield-point.  Therefore, the iterator function will
look something like this (simplified):

    (defun foo-iterator ()
      (let* (outer-scope-x
             to-execute
             (step-1 (lambda ()
                       (setf to-execute step-2)
                       (setf outer-scope-x (bar 1))
                       (throw 'yield outer-scope-x)))
             (step-2 (lambda ()
                       (throw 'yield (+ outer-scope-x (bar 2))))))
        (setf to-execute step-1)
        (build-iterator-object ...)))

Here `outer-scope-x' is the rebinding of `x' needed to somehow
send its value from first step closure to the second.

Iteration

    (let ((iter (foo-iterator)))
      (iter-next iter)
      (iter-next iter))

will then look like (omitting all the internal crap):

    (let ((iter (foo-iterator)))
      (call-to-execute iter)   ; here to-execute = step-1
      (call-to-execute iter))  ; here to-execute = step-2

But remember that the caller of `iter-next' knows nothing about
how iterator internally works and has no idea what it really
does and how it achieves the documented behavior (or doesn't,
when there is a bug).

Paul





      reply	other threads:[~2017-03-20 14:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 13:25 bug#26073: bug in generator function with nested dash anaphoric macros Paul Pogonyshev
2017-03-12 14:05 ` bug#26073: Simplified testcase Paul Pogonyshev
2017-03-19 19:31 ` bug#26073: workaround Paul Pogonyshev
2017-03-20  0:49   ` Stefan Monnier
2017-03-20  9:04     ` Paul Pogonyshev
2017-03-20  9:22       ` Paul Pogonyshev
2017-09-26 14:38         ` Stefan Monnier
2017-09-28 17:18           ` Paul Pogonyshev
2017-09-28 20:07             ` Stefan Monnier
2017-09-28 19:39           ` Philipp Stephani
2017-09-28 20:09             ` Stefan Monnier
2017-11-27 20:34             ` Stefan Monnier
2018-02-09  0:34               ` Noam Postavsky
2018-02-09  2:43                 ` Stefan Monnier
2018-02-15  2:37                   ` Noam Postavsky
2017-03-20 13:25       ` Stefan Monnier
2017-03-20 14:20         ` Paul Pogonyshev [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAG7BpareaWF2pC=inF2cpx-bzo50EQf5gxJaUU3q18UFORTCKg@mail.gmail.com' \
    --to=pogonyshev@gmail.com \
    --cc=26073@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).