map/filter/reduce/lambda opinions and background unscientific mini-survey

Christopher Subich spam.csubich+block at block.subich.spam.com
Fri Jul 8 02:36:35 EDT 2005


Ron Adam wrote:
> Christopher Subich wrote:
> 
>> As others have mentioned, this looks too much like a list 
>> comprehension to be elegant, which also rules out () and {}... but I 
>> really do like the infix syntax.
> 
> 
> Why would it rule out ()?

Generator expressions.  Mind you, Py3k might want to unify generators 
and lists in some way anyway, freeing up (). :)

> 
> You need to put a lambda express in ()'s anyways if you want to use it 
> right away.
> 
>      print (lambda x,y:x+y)(1,2)

Although print <x+y with (x,y)>(1,2) has natural grouping: the lambda 
itself is effectively a single token.  I also like the infix style 
reminiscent of Python's existing comprehensions.

Hell, call it a 'function comprehension' or 'expression comprehension,' 
and we can pretend we invented the damn thing.

> My choice:
> 
>     name = (let x,y return x+y)   # easy for beginners to understand
>     value = name(a,b)
> 
>     value = (let x,y return x+y)(a,b)

And a zero-argument lambda is (aside from really arcane)?
(let return 2)?

> I think the association of (lambda) to [list_comp] is a nice 
> distinction.  Maybe a {dictionary_comp} would make it a complete set. ;-)

Yeah, dictionary comprehensions would be an interesting feature. :) 
Syntax might be a bit unwieldy, though, and I doubt they'd be used often 
enough to be worth implementing, but still neat.



More information about the Python-list mailing list