<div><br></div><div>is there documentation on these Generators?</div><div><br></div><div>i only know the Timothy Budd variety </div><div>     from LittleSmalltalk</div><div>     i guess his variety of Generator</div><div>          was used extensively in LittleSmalltalk</div><div><br></div><div><br></div><div><br></div><div><br><div class="gmail_quote"><div>On Wed, Apr 12, 2017 at 09:52 Levente Uzonyi <<a href="mailto:leves@caesar.elte.hu">leves@caesar.elte.hu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Wouldn't it be better to make Generator >> #do: not use #atEnd?<br>
With the new implementation the following happens:<br>
<br>
| generator |<br>
generator := Generator on: [ :g | ].<br>
generator atEnd<br>
"==> false"<br>
<br>
| generator |<br>
generator := Generator on: [ :g | ].<br>
generator next; atEnd<br>
"==> true"<br>
<br>
Also, this change set will break existing Generator instances if you load<br>
them into your image and it happens to have some.<br>
<br>
Levente<br>
<br>
On Wed, 12 Apr 2017, Bert Freudenberg wrote:<br>
<br>
> Hi all,<br>
> there was an interesting question about Generators on StackOverflow:<br>
><br>
> <a href="http://stackoverflow.com/questions/43340007/yield-prolog-adaptation-for-smalltalk" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/43340007/yield-prolog-adaptation-for-smalltalk</a><br>
><br>
> It's about a pseudo-Prolog implementation using Generators and yield.<br>
><br>
> Our Generator *almost* works for this, except there is a little problem with the timing of side-effects:<br>
><br>
> | x gen |<br>
> x := 0.<br>
><br>
> gen := Generator on: [:g |<br>
> x := 1.<br>
> g yield: nil.<br>
><br>
> x := 2.<br>
> g yield: nil.<br>
><br>
> x := 3.<br>
> g yield: nil].<br>
><br>
> gen do: [:i | Transcript cr; show: x].<br>
><br>
> This *should* print '1 2 3' but actually prints '2 3 3'. This is because our Generator is written to support a streaming interface (using atEnd<br>
> and peek) so it always computes one yield ahead.<br>
><br>
> In other languages (e.g. JavaScript, Python, C#) this is different, the execution is paused at the current yield statement, not 'before' the next<br>
> one. In general, a generator cannot know if there will be more "yields" without executing more code. In Javascript, 'next' returns both a value<br>
> and a 'done' flag, and if the flag is true, the returned value must not be used.<br>
><br>
> IMHO we should fix this - see attached changeset Marcel and I came up with. We did not fix the tests yet, but the behavior seems right.<br>
><br>
> Even though generators are in the image for a long time they are not used widely yet (AFAIK) so maybe we can still change the behavior? What do<br>
> people think?<br>
><br>
> - Bert & Marcel -<br>
><br>
><br>
><br>
<br>
</blockquote></div></div>