[Python-ideas] And now for something completely different

Josiah Carlson josiah.carlson at gmail.com
Thu Sep 18 02:40:44 CEST 2008

On Wed, Sep 17, 2008 at 5:27 PM, Cliff Wells <cliff at develix.com> wrote:
> On Wed, 2008-09-17 at 16:18 -0700, Bruce Leban wrote:
>> On Wed, Sep 17, 2008 at 3:41 PM, Cliff Wells <cliff at develix.com>
>> wrote:
>>         I'd prefer to write
>>         def foo ( lambda: arg ):
>>            return arg # evaluation happens here
>>         foo ( x )
>>         ("lambda" not necessarily being the actual name of the token
>>         in the
>>         second case).
>> I'd rather use the time machine. You can already do this quite
>> easily.
>> def foo (arg):
>>    return arg() # evaluation happens here
>> foo(lambda: x)
> Except I'd prefer not having lambda sprinkled throughout the calling
> code (or worse, forgotten).
>> The idea of something automagically changing from an unevaluated to an
>> evaluated value strikes me as a very bad one so requiring explicit
>> evaluation here is a *good* thing. Aside from that, why should arg be
>> evaluated on return as opposed to being passed along unevaluated until
>> its value is really needed?
> Didn't suggest that.  That was merely an example.  What I'm suggesting
> is that the *first* time it's used, evaluate then (my example used
> return for simplicity).
>>  How would I check to see if an arg was provided? I certainly can't
>> use a default value of None and then check for None since the check
>> would cause it to be evaluated.
> I don't consider that a problem.  You either care about the value of an
> argument or you don't.  If you care then you will eventually evaluate it
> anyway.  If you don't, then don't evaluate it, ever.
>>  Maybe we have a special operator that allows us to look at the
>> unevaluated value. What's the context of the evaluation? Can it access
>> variables in the place where it's evaluated? Maybe there's a special
>> way to do that too.  Let's not go down that path.
> Agreed we shouldn't go down that path, but don't agree that it's needed.

Back when you were talking about statements -> expressions, I was
going to point out deferred function calls, but I also ran into the
"lambda is ugly" problem.

If it weren't for the fact that backticks ` are difficult to
distinguish from regular single quotes ', never mind being a PITA to
type on some keyboards, I would *almost* suggest that backticks should
be used for expressing "a function without arguments, aka a deferred
execution expression".

But then I'd have to give myself a -1, as it violates TOOWTDI.

Then again, the argument could be made that lambdas are just a long
spelling of a def without a name, and that ... add = def (arg1, arg2):
arg1+arg2 would be better.  At that point, we come to def:'deferred' .
 And I think that's ever worse than backticks.

I don't know of a spelling of deferred execution blocks that I would
find reasonable :/ .

 - Josiah

More information about the Python-ideas mailing list