Theoretical question about Lambda

Alex Martelli aleax at aleax.it
Thu May 2 17:05:45 EDT 2002


Bengt Richter wrote:
        ...
>>if doitoneway:
>>    def foo(): return whatever
>>else:
>>    def foo(): return somethingelse
>>
> What if doitoneway varies during expression evaluation involving foo,
> and whatever and somethingelse involve function calls with side effects?

What possible difference does this make?  This if/else has exactly
the same semantics as the and/or/lambda construct somebody else
posted in response -- whatever doitoneway, whatever, AND
somethingelse want to do about it.  I don't really understand what
you mean -- can you give some simple artificial example where
you think lambdas would have different semantics than defs?

> Would you pass all the unevaluated pieces to an outside function? I'm sure
> it would be cleaner sometimes, but I'm not sure about all the time.
> C'mon, you can argue both sides ;-)

I can't argue that lambda lets you do anything substantial that def
doesn't -- there would be just no basis to substain such an argument.
I'm curious to see what you think there might be.


> ISTM a real ternary or cond expression would be a good addition to Python.

Sure, and why not add assignment-in-expression, typed variable
declarations, and block delimiters, as long as we're at it.


Alex




More information about the Python-list mailing list