On Tue, Oct 26, 2021 at 11:44 AM Rob Cliffe via Python-ideas
<[email protected]> wrote:
> I prefer 1). Easier to understand and debug in examples with side-effects
> such as
> def f(a := enter_codes(), b = assign_targets(), c := unlock_missiles(), d
> = FIRE()):
> (not that this is something to be particularly encouraged).
>
It's worth noting that this would call the functions at different
times; assign_targets and FIRE would be called when the function is
defined, despite not entering the codes and unlocking the missiles
until you actually call f().
The difference between early evaluation and late evaluation is that
one retains the *value* and the other retains the *expression*. So
it's something like:
_b_default = assign_targets(); _d_default = FIRE()
def f(a, b, c, d):
if a is not set: a = enter_codes()
if b is not set: b = _b_default
if c is not set: c = unlock_missiles()
if d is not set: d = _d_default
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/FSOGHASHZMAHGKAL4HTEJKAV2HKYTLD4/
Code of Conduct: http://python.org/psf/codeofconduct/