<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 16, 2017 at 11:15 PM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><span style="font-size:11.2px"><font face="arial, helvetica, sans-serif">This also means that a 'delayed' object needs to be idempotent. So</font></span></div><div><span style="font-size:11.2px"><font face="arial, helvetica, sans-serif"><br></font></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-size:11.2px"><font face="monospace, monospace">x = delayed 2+2</font></span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-size:11.2px"><font face="monospace, monospace">y = delayed x</font></span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-size:11.2px"><font face="monospace, monospace">z = delayed delayed delayed y</font></span></div></blockquote><font face="arial, helvetica, sans-serif"><span style="font-size:11.2px"><br></span></font><div><font face="arial, helvetica, sans-serif"><span style="font-size:11.2px">Wrapping more delays around an existing delayed object should probably just keep the same object rather than "doubly delaying" it. If there is some reason to create separate delayed objects that isn't occurring to me, evaluating 'z' would still go through the multiple evaluation levels until it got to a non-delayed value.</span></font></div></div></blockquote><div><br></div><div>This is sort of like how iterators "return self" and 'it = iter(it)'.</div><div><br></div><div>In the case of Dask, wrapping more delayed objects creates layers of these lazy objects. But I think it has to because it's not part of the syntax. Actually, I guess Dask could do graph reduction without actual computation if it wanted to. But this is the current behavior:</div><div><br></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">>>> def unchanged(x):</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">... return x</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">>>> a = delayed(unchanged)(42)</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">>>> a</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">Delayed('unchanged-1780fed6-f835-4c31-a86d-50015ae1449a')</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">>>> b = delayed(unchanged)(a)</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">>>> c = delayed(unchanged)(b)</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">>>> c</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">Delayed('unchanged-adc5e307-6e33-45bf-ad73-150b906e921d')</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">>>> c.dask</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">{'unchanged-1780fed6-f835-4c31-a86d-50015ae1449a': (<function __main__.unchanged>,</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> 42),</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> 'unchanged-adc5e307-6e33-45bf-ad73-150b906e921d': (<function __main__.unchanged>,</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> 'unchanged-c3282bc4-bdaa-4148-8509-9155cac83ef0'),</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> 'unchanged-c3282bc4-bdaa-4148-8509-9155cac83ef0': (<function __main__.unchanged>,</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> 'unchanged-1780fed6-f835-4c31-a86d-50015ae1449a')}</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"><br></font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">>>> c.compute()</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">42 </font></div></div></div></blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">Actually Dask <b>cannot</b> know that "unchanged()" is the function that makes no transformation on its one parameter. From what it can see, it's just a function that does <b>something</b>. And I guess similarly in the proposed syntax, anything other than a plain name after the 'delayed' would still need to create a new delayed object. So it's all an edge case that doesn't make much difference.<br clear="all"><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>