(Yes, I know I'm really overstaying my welcome in this ng, just
"trolling" a 0.02E more)

>>>>> "Sinclair" == Gavin Sinclair <gsinclair / soyabean.com.au> writes:

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

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

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

And truly, I don't see anything wrong with that code. It's not
'perlish', it's the plain old functional way of doing things. It's
chaining just like with method calls.

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

    Sinclair> I argue that Ruby's is better because it's more general
    Sinclair> (provides features beyond mere iteration), more OO (thus
    Sinclair> a better fit with the language), and more high-level
    Sinclair> (see below).  The different approaches

Blocks provide iteration and anonymous functions. Both exist in
Python. And if the needs of your anonymous function exceed what lambda
provides, you can use what I call big L notation:

def L(matchobj):
    return matchobj.group(0).upper()

res = re.sub('u|a', L, 'huijaahuijaa')

    Sinclair> I dislike being given iterable ojects for everything.
    Sinclair> That means you're doing explicit iteration, whereas Ruby
    Sinclair> gives you implicit iteration.  Implicit is definitely
    Sinclair> better than explicit in this case: it gives you
    Sinclair> higher-level code without any sacrifice in power.  It

Perhaps some of us like to do our iteration explicitly. I don't think
there is any syntactic overhead, and the for loop reads
better. Counterexamples welcome.

Obviously we can do #each too:

def L(x):
    print x
    return x*2

map(L, [1,2,3])

But plain old for loop is more convenient, esp. if you don't need to
generate a result list in the process.


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

Oh, please. That wouldn't be true even if Ruby afficiandos kept
repeating it 10 times a day (it could even become the new "Python OO
is a hack"). Ruby and Python are pretty much exactly on the same level
abstraction-wise. Ruby is higher level than Python in the sense Perl
is higher level than Python, i.e. it provides some "conveniences" of
questionable utility like regexps in language syntax and multiple
methods doing the same thing.

-- 
Ville Vainio   http://tinyurl.com/2prnb