[Python-ideas] Alternative to PEP 532: delayed evaluation of expressions

Steven D'Aprano steve at pearwood.info
Mon Nov 7 00:46:22 EST 2016


On Sun, Nov 06, 2016 at 09:31:06AM -0500, Eric V. Smith wrote:

> The point remains: do we want to be able to create unevaluated 
> expressions that can be evaluated at a different point?

I sometimes think that such unevaluated expressions (which I usually 
call "thunks") would be cool to have. But in more realistic moments I 
think that they're a solution looking for a problem to solve.

If your PEP suggests a problem that they will solve, I'm interested.

But note that we already have two ways of generating thunk-like objects: 
functions and compiled byte-code.

thunk = lambda: a + b - c
thunk()

thunk = compile('a + b - c', '', 'single')
eval(thunk)

Both are very heavyweight: the overhead of function call syntax is 
significant, and the keyword "lambda" is a lot of typing just to delay 
evaluation of an expression. compile(...) is even worse.


-- 
Steve


More information about the Python-ideas mailing list