v0.29
You can assign the value of a Python expression to a variable, e.g.
x = (5 + 6)assigns 11 to the variable x. The RHS, (5 + 6) is shorthand for (lambda: 5 + 6). In other words,
the expression inside the parens is evaluated, and the resutling value is assigned.
Sometimes you want to assign a function to a variable. Following the previous example, you would
have to do something like this to create a function that adds 1 to a number:
inc = (lambda: lambda x: x + 1)Evaluating (lambda: lambda x: x + 1) yields the function lambda x: x + 1 which is assigned to
inc. That is kind of clunky, and while obviously correct and consistent, it isn't what you
normally think of first. Or at least I didn't, I tried inc = (lambda x: x + 1) and got an error
message because (lambda x: x + 1) cannot be evaluated without binding a value to x.
In this release, the less clunky, less consistent syntax is permitted. If you write:
inc = (lambda x: x + 1)then inc will be assigned lambda x: x + 1. I.e., it will be understood that you really
meant inc = (lambda: lambda x: x + 1). This only happens when assigning expressions
to variables. In other contexts, (e.g. the function used with map or select), there
is no similar tweaking of the expression.