il Mon, 5 Apr 2004 02:42:16 +0900, Gavin Sinclair
<gsinclair / soyabean.com.au> ha scritto::


>#each is not just a for loop.  #each is the embodiment of Ruby's
>ability to provide arbitrary abstraction layers using blocks.
>Functionally, it may be a for loop, but suggesting they're equivalent
>is missing an important point.
<snip>

As of current python, you have equivalent mechanics for yield as an
iterator thing.
each_with_index is enumerate(iterable).
Select is ifilter(), and there is imap() and there are equivalents for
many other things. 


Ruby iterator/blocks and python iterators/generator are very different
approaches that yield similar results somehow, but both are really
valuable and I don'tn think one is inherently better than the other. 


Obviously, in ruby there are blocks for everything cause ruby had them
since the beginning, see the gsub example. 
But note that python has a re.finditer() that allows you to get an
iterable object with the match inside.

I love blocks as a useful lambda form and extension mechanism, say, I
love this:

>> def with(obj,&blk)
>>  obj.instance_eval(&blk)
>> end
=> nil
>> with(mio=Object.clone) do
?>  def f
>>   print 'foo'
>>  end
>> end
=> nil
>> mio.f
foo=> nil

(dirty prototyping ruby 8-)

but for what relates to iteration I believe python is getting ruby.