* generator documentation improvement
@ 2017-03-08 20:47 Paul Pogonyshev
2017-03-08 21:06 ` Noam Postavsky
0 siblings, 1 reply; 4+ messages in thread
From: Paul Pogonyshev @ 2017-03-08 20:47 UTC (permalink / raw)
To: emacs-devel
[-- 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: generator documentation improvement
2017-03-08 20:47 generator documentation improvement Paul Pogonyshev
@ 2017-03-08 21:06 ` Noam Postavsky
2017-03-08 21:28 ` Andreas Politz
0 siblings, 1 reply; 4+ messages in thread
From: Noam Postavsky @ 2017-03-08 21:06 UTC (permalink / raw)
To: Paul Pogonyshev; +Cc: Emacs developers
On Wed, Mar 8, 2017 at 3:47 PM, Paul Pogonyshev <pogonyshev@gmail.com> wrote:
>
> 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.
Is this Bug#25965 "iter-lambda may evaluate certain forms twice"?
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25965
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: generator documentation improvement
2017-03-08 21:06 ` Noam Postavsky
@ 2017-03-08 21:28 ` Andreas Politz
2017-03-11 21:10 ` Paul Pogonyshev
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Politz @ 2017-03-08 21:28 UTC (permalink / raw)
To: Noam Postavsky; +Cc: Paul Pogonyshev, Emacs developers
Noam Postavsky <npostavs@users.sourceforge.net> writes:
> Is this Bug#25965 "iter-lambda may evaluate certain forms twice"?
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25965
Yes, it is.
Are sure that "iter-yield [...] cannot appear inside [...] dynamic let
bindings" is the intended behavior ? There is special code in
generator.el handling these dynamic bindings, which I think is just
incorrect.
-ap
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: generator documentation improvement
2017-03-08 21:28 ` Andreas Politz
@ 2017-03-11 21:10 ` Paul Pogonyshev
0 siblings, 0 replies; 4+ messages in thread
From: Paul Pogonyshev @ 2017-03-11 21:10 UTC (permalink / raw)
To: Andreas Politz; +Cc: Emacs developers, Noam Postavsky
> Are sure that "iter-yield [...] cannot appear inside [...] dynamic let
> bindings" is the intended behavior ?
No, I just assumed it was related. I noticed weird behaviour in
real code and managed to pinpoint it to let-binding global variables.
Local (lexical scope) bindings are not a problem. I guessed that
global variable binding are in some sense similar to `unwind-protect',
since no matter how you exit body of `let' (normally or with an error),
previous value must be restored.
If it is not intended and can be fixed, then of course the
documentation patch is not needed.
Paul
On 8 March 2017 at 22:28, Andreas Politz <politza@hochschule-trier.de> wrote:
> Noam Postavsky <npostavs@users.sourceforge.net> writes:
>
>> Is this Bug#25965 "iter-lambda may evaluate certain forms twice"?
>>
>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25965
>
> Yes, it is.
>
> Are sure that "iter-yield [...] cannot appear inside [...] dynamic let
> bindings" is the intended behavior ? There is special code in
> generator.el handling these dynamic bindings, which I think is just
> incorrect.
>
> -ap
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-11 21:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-08 20:47 generator documentation improvement Paul Pogonyshev
2017-03-08 21:06 ` Noam Postavsky
2017-03-08 21:28 ` Andreas Politz
2017-03-11 21:10 ` Paul Pogonyshev
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.