Confessions of a Python fanboy

Luis Zarrabeitia kyrie at uh.cu
Thu Jul 30 23:57:48 CEST 2009


On Thursday 30 July 2009 04:41:57 pm Masklinn wrote:
> On 30 Jul 2009, at 22:23 , Jan Kaliszewski wrote:
> > 30-07-2009 o 13:36:49 Masklinn <masklinn at masklinn.net> wrote:
> >
> > I don't see any real limitation. What's wrong in:
> >
> > for localVar in container:
> >    block
>
> Well what's wrong with using that rather than `map`, `filter` or a
> list comprehension?

As I understood the question, it was "was wrong in 'for var in container' in 
comparison with ruby's container.each?"

What's the (semantic) difference between

for localVar in container:
    block

and

container.each{|localVar| block}

?

(the sintactic difference is quite clear... if there is no semantic 
difference, I'd rather use the first version!)

Map, filter and comprehensions have little to do with that (syntactic sugar 
that may allow some optimizations, but that could otherwise be replaced by 
the for loop).

> (and if you don't see what the limitations of 
> `lambda` are, you probably very rarely use it)

I'm not the poster, but: 
* I use lambdas, a lot.
* I "know" python lambdas are limited, compared with theoretical lambdas.
* I don't [usually] see that as a "limitation".

Most of the time, the limitation is the lack of multiline/multiexpression 
lambdas. But I've never seen a case where I would /prefer/ to have a 
multiline function definition inside a comprehension or method invocation, 
instead of a named function defined two lines before it.

(The second famous limitation is the inability to use statements inside 
lambdas... luckily, now that we have a ternary operator and a print function, 
it is less limiting)

> > And ruby's container.each is very similar to Python's iter()
>
> Uh… not at all…

I agree with this. It should have said that they are equivalent in the sense 
that they represent the iterator protocols of both languages, and nothing 
more.

I'd like to ask, what "container.each" is, exactly? It looks like a function 
call (as I've learned a few posts ago), but, what are its arguments? How the 
looping "works"? Does it receive a "code" object that it has to execute? 
Is .each some kind of magic keyword? (This has little to do with python or 
the current thread, so feel free to reply off-list if you want to...)

Regards,

Luis.

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie



More information about the Python-list mailing list