[Python-ideas] Another way to avoid clumsy lambdas, while adding new functionality

Steven D'Aprano steve at pearwood.info
Wed Mar 5 12:32:33 CET 2014


On Wed, Mar 05, 2014 at 12:46:11PM +1100, Cameron Simpson wrote:

> That makes me think the (()) or $() is in the wrong place. Maybe:
> 
>     a := foo + 1

No good. That implies that there is no way to have an anonymous thunk. 
You can do this:

my_list = [x + 1, y + 2,   # eager evaluation
           $(z + 3),  # lazy evaluation
            ... ]

but would have to write:

temp := z + 3
my_list = [x + 1, y + 2, temp, ...]


Similarly for passing a thunk into a function.



> Since I'm cavilling about "eval", how about just treating thunks
> like other functions (which is how we spell code to be run later
> presently) and have them be callables. 

In which case, what's the point? What makes them different from regular 
functions?



-- 
Steven


More information about the Python-ideas mailing list