Counting from zero

Ralph Johnson johnson at cs.uiuc.edu
Tue May 2 06:52:26 UTC 2006


On 5/2/06, Duncan Mak <duncanmak at gmail.com> wrote:

> However, I ran into trouble when I had to iterate two collections together,
> but each at a different offset, i..e  matching a[i] to  b[i + 2]. My
> solution in the end was to use a named let, which is not quite the same as a
> for loop in C, but if I were writing this in Smalltalk I wouldn't know how
> to do it with only do:, collect:, select:, etc either.

Probably you should use Streams.  If you think about this from a
pattern point of view, internal iterators (do: and friends) are easier
to use than external iterators (Stream and children) but external
iterators are more powerful.  In particular, if you have to process
several collections at once then you usually need to use Streams.  The
Collection class has with:do:, which is sometimes enough to process
two collections at a time, but the need to use several collections is
a sign that you should think about Streams.

-Ralph Johnson



More information about the Squeak-dev mailing list