[squeak-dev] generators

Eliot Miranda eliot.miranda at gmail.com
Tue Jun 23 18:23:27 UTC 2020


Hi All,

    I juts had occasion to use generators in anger for the first time.  I
was trying to fnd out why a clone of a prse tree was reporting that it was
not the same tree.  Generators made enumerating all nodes in each tree
together trivial:

| them |
them := Generator on: [:g| newTree nodesDo: [:n| g yield: n]].
parseTree nodesDo:
[:n| | twin |
twin := them next.
(n isSameAs: twin) ifFalse:
[self halt]]

My message though comes from noticing that generators yield their values
via next, so why not use nextPut: instead of yield: ?

e.g. I think this is better:

| them |
them := Generator on: [:g| newTree nodesDo: [:n| g nextPut: n]].
parseTree nodesDo:
[:n| | twin |
twin := them next.
(n isSameAs: twin) ifFalse:
[self halt]]

_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200623/3ccd3968/attachment.html>


More information about the Squeak-dev mailing list