all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmail.com>
To: emacs-devel@gnu.org
Subject: generator documentation improvement
Date: Wed, 8 Mar 2017 21:47:43 +0100	[thread overview]
Message-ID: <CAG7Bpao-p8ZYGzT6NH3v9i+UJRjY3ccM-si2fkjEUzuPNe4=ng@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 639 bytes --]

I suggest the following short improvement to documentation of
generator functions.  It took me very long to understand what's wrong
with my code.

Problem can be illustrated with this:

(require 'generator)
(defvar xxx 0)
(iter-defun my-iter ()
  (print "A")
  (let ((xxx nil))
    (print "B")
    (iter-yield 0)
    (print "C"))
  (print "D"))
(iter-do (x (my-iter))
  (print x))

If you evaluate the last form, you'll see "B" and "C" printed twice
because `let' for dynamic variable is internally implemented with
something similar to `unwind-protect'. However, when documentation
doesn't mention it, that's very hard to pinpoint.

Paul

[-- Attachment #2: generator-doc.diff --]
[-- Type: text/plain, Size: 506 bytes --]

diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index 401a999cf2..e279be8557 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -730,7 +730,8 @@ result as its condition data.
 
 Any kind of Lisp code is valid inside @var{body}, but
 @code{iter-yield} and @code{iter-yield-from} cannot appear inside
-@code{unwind-protect} forms.
+@code{unwind-protect} forms or any dynamic @code{let} bindings,
+i.e. bindings for variables defined with @code{defvar}.
 
 @end defmac
 

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-08 20:47 Paul Pogonyshev [this message]
2017-03-08 21:06 ` generator documentation improvement Noam Postavsky
2017-03-08 21:28   ` Andreas Politz
2017-03-11 21:10     ` Paul Pogonyshev

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='CAG7Bpao-p8ZYGzT6NH3v9i+UJRjY3ccM-si2fkjEUzuPNe4=ng@mail.gmail.com' \
    --to=pogonyshev@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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.