On 2016-06-01 16:50, Jonathan Goble wrote:
I have a completely different idea here. Forget clunky syntax, overloading of 'def' and 'as', and all that. Introduce the magic parameter '$'. To wit:
def func(*args, **kwargs, $): # positioning of the $ is discussed
below ... # function code here
$ would be a special-cased parameter that does not receive an explicit argument, and is thus ignored when calling the function (i.e. the function above would be called simply as 'func(*args, **kwargs)'). Instead, the $ parameter receives as its value a string representing the name that the function's return value will be bound to, or None if the function is called as a statement (where the return value is simply thrown away).
I think that's way too general and dangerous. I don't want arbitrary objects to be able to do arbitrary things based on what name I'm assigning them to. I think the fact that Python doesn't allow overriding simple assignment, although it makes some things difficult, makes it simpler to reason about in many cases. If we do add something to handle this case, I'd rather it be something explicit, so you know when you're crossing the barrier between identifiers and string values.