----- Original Message ----- 
From: "Bruce Williams" <bruce / codedbliss.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Wednesday, January 22, 2003 4:31 PM
Subject: Re: Definition: iterator


What is an iterator? Hmmm.

Well, I don't have a good definition. I think
the FOLDOC definition is a little different
from how we think of things in Ruby.

I would define it by its operation rather than
its usage -- something like "a method with the
internal capability of calling a code block
associated with the method call, in such a way
that the method and the block trade control 
back and forth like coroutines."

This is general enough that it even covers
what I call the "non-iterating iterator."
This comes in one or two varieties, but the
most common/intuitive is the "open-close" 
kind. See File#open for an example, or 
Mutex#synchronize, or the newer form of
Dir.chdir (1.7.x).

I think another kind of non-iterating iterator
occurs in cgi.rb, where blocks are basically
used for string data -- don't really recall
how it works.

Cases like this make the term "iterator" 
somewhat inappropriate, of course... but
no one seems to complain about it.

Hal