[Python-ideas] And now for something completely different

Cliff Wells cliff at develix.com
Thu Sep 18 02:27:38 CEST 2008


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.

Cliff




More information about the Python-ideas mailing list