[Python-ideas] Delayed Execution via Keyword

David Mertz mertz at gnosis.cx
Sat Feb 18 00:45:48 EST 2017


On Fri, Feb 17, 2017 at 5:23 PM, Steven D'Aprano <steve at pearwood.info>
wrote:

>
> try:
>     Aardvark
> except NameError:
>     from backport import Aardvark
>
> No such thing is possible for new syntax. So that counts as a
> disadvantage of new syntax. Are we positive that there *must* be new
> syntax to solve this problem?
>

I agree it counts as a disadvantage.  But Dask and lazy, and even just
using lambdas as "thunks" push what we can do as far as we can without
syntax.  Those will always require a `obj.compute()` or `obj()` or
`eval(obj)` or something else like that to force the "thunk" to concretize.


> I think side-effects is a red herring. The obvious rule is: side-effects
> occur when the delayed thunk is reified. If you care about the actual
> timing of the side-effects, then don't use delayed evaluation. If you
> don't care, then who cares if the side-effect is delayed?
>

Exactly! The same rule applies when writing any computational functions
too.  If you worry whether they are pure, don't have side effects.  Or if
you don't care about the side-effects too much (for example, when or if
they happen specifically), that's fine and accept it.


> > So far I'm going with pretty much anything that isn't being the
> right-hand
> > of an assignment. So coercion to different types, hashing (for use as a
> key
> > in a dict or set), __repr__, etc would all be covered, as well as
> identity
> > and comparisons. i.e.:
> [...]
>
> That will make it pretty much impossible to tell whether something is a
> delayed "thunk" or not, since *any* attempt to inspect it in any way
> will cause it to reify. Maybe that's what we want.


This feels like a disadvantage, and an important one.  Most "normal"
programmers should never have to care whether something is delayed or has
been concretized already.  But people writing debuggers, profilers, etc.
really do want to know.

There should be some way at poking at an object if you really want to
without concretizing it.  I wouldn't care if this was some ugly and obscure
device like 'inspect._is_delayed(my_obj._co_delayed)' that has different
semantics than other function calls.  Maybe "the uglier the better" in this
case, since it *should* be reserved for special purposes only.

-- 
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/20170217/b57c9363/attachment.html>


More information about the Python-ideas mailing list