Securing a future for anonymous functions in Python

Nick Coghlan ncoghlan at iinet.net.au
Thu Dec 30 22:22:35 EST 2004


Michael Spencer wrote:
> while we're at it, perhaps 'for' would be more appropriate:
> 
>     (expression for args(a, *args, **kw))

Hmm, what about an 'abbreviated generator expression' syntax:

(<expression> for <args-tuple>)

For instance:

(f(a) + g(b) - h(c) for (a, b, c))

(the 'in' clause of the standard generator expression is missing).

That does leave the question of the correct spelling of 'no arguments', which 
generator expressions don't have to deal with. Perhaps:

(f.close() for ())

It does make for an interesting interpretation of the generator expression syntax:

(<expression> for <args-tuple> in <sequence> if <condition>)

def expression_func(<args-tuple>):
   return <expression>

def generator():
   for <args-tuple> in <sequence>
     if <condition>:
       yield expression_func(<args-tuple>)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list