A replacement for lambda

Paul Rubin http
Sat Jul 30 15:04:23 EDT 2005


Seth Nielson <sethjn at gmail.com> writes:
> Any replacement must support the following: *delayed evaluation*.
> 
> I need a convenient (def is not always convenient) way of saying,
> "don't do this now". That is why I use lambda.

How's this: f{args} (curly braces instead of parens) is the same as
f(lambda: args).

Examples:

    launch_thread{targetfunc(a,b,c)}

    b = Button{callback=pressed()}   # Button remembers callback()

    def ternary(cond, x, y):
       if cond(): return x()
       else: return y()

    sign_of_a = ternary{a < 0, -1, 1}


etc.



More information about the Python-list mailing list