----- Original Message ----- 
From: "Martin DeMello" <martindemello / yahoo.com>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Wednesday, January 22, 2003 5:21 PM
Subject: Re: Definition: iterator


> Hal E. Fulton <hal9000 / hypermetrics.com> wrote:
> > 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."
> 
> I'd distinguish iterators from the general case of yield-calling
> methods, personally. A first approximation to the definition I'd use:
> 
> A method that takes in a block, and calls it on successive elements of a
> collection.

Yes, in a sense I agree. 

I do wish we had a name for "methods that 
call yield." In Ruby we've traditionally
called them "iterators" (witness the 
iterator? method as David pointed out).

That's a misleading usage, but don't blame
me for it. I didn't originate it.

<not_really_serious>
But on the other hand: What is a "collection"?
You say "successive" elements. Well, what 
about this:
  [1].each {|x| puts x}
It doesn't operate on successive elements. There
aren't any successive elements. There is only
one.

We could perhaps view the other cases in a similar
way -- File.open acts on a collection of files
(containing only one file). Mutex#synchronize 
iterates through a list containing one mutex.
And so on. If you only loop once, are you really
iterating? Or just irritating? What is the sound
of one hand clapping? What is the speed of sound
in a vacuum? Where does your lap go when you
stand up?
</not_really_serious>


Hal