
On 2021-10-25 3:31 p.m., Mike Miller wrote:
"defer" please.
This construct did not happen in the past, and it's shorter of course.
-Mike
I also like `defer`:
def range(a, min=0, max = defer len(a)): return a[min:max]
`default` is also nice:
def range(a, min=0, max default len(a)): return a[min:max]
I was concerned with this proposal at first because an inner function definition may be ambiguous:
def do_work(): a = ['this', 'is', 'a', 'list'] def range(a, min=0, max = defer len(a)): return a[min:max]
which `a` does `len(a)` refer to? Looking through my code, it seems this is not a problem; outer method variables rarely conflict with inner method parameters in practice. Can deferred defaults refer to variables in scope? Can I use this to evaluate arguments lazily?
def coalesce(a, b): def _coalesce(x = defer a(), y = defer b()): if x is None: return x return y _coalesce()
def expensive_method(): return 84
print(coalesce(lambda: 42, expensive_method))
Thank you