On 26/10/2021 02:12, Chris Angelico wrote:
On Tue, Oct 26, 2021 at 11:44 AM Rob Cliffe via Python-ideas
<python-ideas@python.org> 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
You're right, I wasn't thinking clearly.  It would have been a better example if I had used late binding for ALL arguments.
(Still, I averted a nuclear war, albeit accidentally. 😁)
Rob

_______________________________________________
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/IXXK2T2UEV3T7D7PZ25ICVUR6C4CHXTQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to