Guido van Rossum wrote:
Note that 'property' and 'synchronized' used as examples are not new keywords! They are just built-in objects that have the desired semantics and know about thunks.
This seems really elegant. I hope it can be worked out.
One thing I find mildly disconcerting is the restriction that nothing can follow the thunk.
If you can do this:
a = thunkuser: thunk
It seems like you should be able to do this (however unwieldy it looks):
a,b = (thunkuser: thunk ), thunkuser: thunk
And once you allow one-line thunks, following them in an expression won't seem quite as unwieldy:
a,b = (thunkuser: thunk), (thunkuser: thunk)
My discomfort is an artifact of allowing thunks to be used in expressions. The restriction seems perfectly reasonable in these contexts:
What's still missing is a way to add formal parameters to the thunk -- I presume that J and K are evaluated before interface.interface is called. The thunk syntax could be extended to allow this; maybe this can too. E.g.:
e:(x, y): S
would create a thunk with two formal parameters, x and y; and when e calls the thunk, it has to call it with two arguments which will be placed in x and y. But this is a half-baked idea, and the syntax I show here is ambiguous.
Doesn't lambda already accomplish this? Everything between "lambda" and ":" is interpreted as an argument list.
In the same light, def stores the function name, interprets the argument list, and sets the function body to the thunk code. Perhaps the following could be equivalent:
def func(args): body
def(func) lambda args: body