
On Thu, Nov 4, 2021 at 5:54 AM Ethan Furman <ethan@stoneleaf.us> wrote:
On 11/3/21 12:13 AM, Chris Angelico wrote:
Python has a strong policy of evaluating things immediately, or being very clear about when they will be evaluated
Putting the marker in the middle of the name binding expression is not "very clear" -- particularly since the advice is "ne spaces around '=' in function headers and calls".
Not sure what you mean, but the distinction, if I'm interpreting your statement correctly, is actually the same as there will be with different languages. For instance, I tried this in JavaScript (specifically in Node.js):
function f(a=console.log("Evaluating a")) { ... console.log("Function body begins"); ... console.log("a is", a); ... } undefined f() Evaluating a Function body begins a is undefined undefined
Evaluating the argument default as the function begins makes perfect sense. Evaluating the argument default when you *refer to* the variable in question does NOT make sense. (In the JS example, that would be having "Function body begins" before "Evaluating a".) Proposals to have generic deferreds that get calculated when referenced would be incredibly surprising. "Immediately", when code is written in the function header, can be interpreted as "when the function is created" or "when the function is called", but should not be interpreted as "when you use this variable". ChrisA