On Monday, April 5, 2004, 7:24:18 AM, gabriele wrote:

> 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. 

It's not equivalent.  Ruby's approach is more OO: you can chain
methods.  What you present on Python's side are functions.  To combine
those in a meaningful way, I foresee list comprehensions :)  Or the
good old Perlish:

  for s in uniq(sort(map(grep(........)))))  :)

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

I argue that Ruby's is better because it's more general (provides
features beyond mere iteration), more OO (thus a better fit with the
language), and more high-level (see below).  The different approaches
have different side-effects, and in terms of power and even
aesthetics, Ruby has nailed this one dead on.

> 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 dislike being given iterable ojects for everything.  That means
you're doing explicit iteration, whereas Ruby gives you implicit
iteration.  Implicit is definitely better than explicit in this case:
it gives you higher-level code without any sacrifice in power.  It
removes swathes of boiler-plate code from the programmer's view without any
loss of context, intention, or nuance.  It puts the important code in
from of the programmer and the repetitive code in the background.

Don't get me wrong, Python is a high-level language.  But Ruby is a
very high-level language.

Cheers,
Gavin