On Thu, Nov 4, 2021 at 5:54 AM Ethan Furman <et...@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
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/67NF4IZYG4BNE7MPFJCSAELWWGIXV3NV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to