On 2021-10-26 at 12:12:47 +1100,
Chris Angelico <ros...@gmail.com> 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().

So much for evaluating default values from left to right; this could be
trouble even if the functions themsevles don't have side effects, but
merely access data that has been mutated between function definition
time and function call time.  Requiring that all late bound defaults
come after all early bound defaults (which has already come up as a
possibility) seems like a reasonable solution.

> 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

Is the phrase/concept "retains the expression" new?  Unless it's really
a new concept, is there an existing way to say that?
_______________________________________________
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/OH3XLE5AUR77GOZDTE3KJBZL33RCJ4WA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to