[Python-ideas] Delayed Execution via Keyword

Joseph Hackman josephhackman at gmail.com
Sun Feb 19 13:47:34 EST 2017


>
> This doesn't make sense.  Function definition time is very different than
> function execution time.  Changing that distinction is a WAY bigger change
> than I think we should contemplate.
> Moreover, there is a completely obvious way to spell the behavior you want:
> def stuff():
>     arg = f()
>     # ... whatever ...
> This is exactly the obvious way to spell "f() is called every time stuff()
> is".


I think it would be useful, but yeah, it really doesn't fit in with the
rest of lazy/delayed. The present format of defaulting to none and then
doing if arg is None: is totally functional.
On the flip side, doing a lazy in the function definition would save time
evaluating defaults while also fitting in.

Your argument has convinced me, and I now take (what i believe to be) your
position:

def stuff(arg = lazy f()):

should result in a function where the default value of arg is not evaluated
until first function call, and then the value of the expression is used as
the default.

Now, back to  what Michel was probably actually asking.
In the case of:

def stuff(arg = lazy []):
is the default value of arg a new list with each execution? (i.e. the
resulting value of the expression is `make a new list`)

I would say that for consistency's sake, not, which I believe would be
consistent with the logic behind why default values being [] are kept
between calls.

a = lazy []
b = a
a.append('a')
print(b) # expected behavior is ['a']

I maintain that it would be nice for there to be a way to say (the default
value of this argument is to run some expression *every time*), but
delayed/lazy probably isn't that.











On 19 February 2017 at 13:33, David Mertz <mertz at gnosis.cx> wrote:

> On Sun, Feb 19, 2017 at 10:13 AM, Joseph Hackman <josephhackman at gmail.com>
> wrote:
>>
>> My honest preference would be that the [] is evaluated fresh each time
>> the function is called.
>> def stuff(arg=delayed f()):
>> would result in f() being called every time stuff() is. This seems more
>> valuable to me than just doing it once when the function is first called.
>>
>
> This doesn't make sense.  Function definition time is very different than
> function execution time.  Changing that distinction is a WAY bigger change
> than I think we should contemplate.
>
> Moreover, there is a completely obvious way to spell the behavior you want:
>
> def stuff():
>
>     arg = f()
>
>     # ... whatever ...
>
>
> This is exactly the obvious way to spell "f() is called every time stuff()
> is".
>
>
> --
> Keeping medicines from the bloodstreams of the sick; food
> from the bellies of the hungry; books from the hands of the
> uneducated; technology from the underdeveloped; and putting
> advocates of freedom in prisons.  Intellectual property is
> to the 21st century what the slave trade was to the 16th.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170219/3fb8b003/attachment.html>


More information about the Python-ideas mailing list