<div style="white-space:pre-wrap">Yikes. Not too concerned about the infinite loop issue, as floating point strides when fixed to avoid error accumulation will necessarily enforce a finite number of steps. However, you&#39;re talking a regular, not-at-all-lazy Array being returned? That would be not good at all...<br></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Apr 10, 2016 at 12:29 AM Dave via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Apr 9, 2016, at 4:33 AM, Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><div>While I’m in favour of the basic idea I think the operator selection is too complex, and I’m not sure about the need for negative strides. Really all I want are the following:</div><div><br></div><div><font face="Monaco"><span style="white-space:pre-wrap">        </span>(0 ... 6).striding(by: 2)<span style="white-space:pre-wrap">        </span>// [0, 2, 4, 6]<span style="white-space:pre-wrap">                </span>x from 0 to 6</font></div><div><font face="Monaco"><span style="white-space:pre-wrap">        </span>(0 ..&lt; 6).striding(by: 2)<span style="white-space:pre-wrap">        </span>// [0, 2, 4]<span style="white-space:pre-wrap">                </span>x from 0 while &lt;6</font></div><div><font face="Monaco"><span style="white-space:pre-wrap">        </span>(6 ... 0).striding(by: 2)<span style="white-space:pre-wrap">        </span>// [6, 4, 2, 0]<span style="white-space:pre-wrap">                </span>x from 6 to 0</font></div><div><font face="Monaco"><span style="white-space:pre-wrap">        </span>(6 ..&gt; 0).striding(by: 2)<span style="white-space:pre-wrap">        </span>// [6, 4, 2]<span style="white-space:pre-wrap">                </span>x from 6 while &gt;0</font></div><div><br></div><div>Everything else should be coverable either by flipping the order, or using .reverse(). The main advantage is that there’s only one new operator to clarify the 6 ..&gt; 0 case, though you could always just reuse the existing operator if you just interpret it as “x from 6 to, but not including, 0&quot;</div></div></div></blockquote></div><br></div><div style="word-wrap:break-word"><div>`.reverse()` returns an array, though, not a StrideTo&lt;&gt;, which means it’ll get in an infinite loop on infinite sequences. This works fine:</div><div><span><span><div style="font-family:Menlo;margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><span style="color:#bb2ca2">for</span><span> i </span><span style="color:#bb2ca2">in</span><span> </span><span style="color:#31595d">stride</span><span>(from: </span><span style="color:#272ad8">0.0</span><span>, to: </span><span style="color:#703daa">Double</span><span>.infinity, by: </span><span style="color:#703daa">M_PI</span><span>) {</span></div><div style="margin:0px;line-height:normal;color:rgb(49,89,93)"><span style="color:#000000">    </span><span style="color:#bb2ca2">if</span><span style="color:#000000"> </span><span>someTestInvolving</span><span style="color:#000000">(i) { </span><span style="color:#bb2ca2">break</span><span style="color:#000000"> }</span></div><div style="margin:0px;line-height:normal"><span>    ...</span></div><div style="margin:0px;line-height:normal"><span>}</span></div><div><span><br></span></div></div><div><span>But this never even starts executing the loop because of the infinite loop inside `.reverse()`:</span></div><div><span><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">for</span><span> i </span><span style="color:#bb2ca2">in</span><span> </span><span style="color:#31595d">stride</span><span>(from: -</span><span style="color:#703daa">Double</span><span>.infinity, to: </span><span style="color:#272ad8">0.0</span><span>, by: </span><span style="color:#703daa">M_PI</span><span>).</span><span style="color:#3d1d81">reverse</span><span>() {</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:#000000">    </span><span style="color:#bb2ca2">if</span><span style="color:#000000"> </span><span>someTestInvolving</span><span style="color:#000000">(i) { </span><span style="color:#bb2ca2">break</span><span style="color:#000000"> }</span></div><div style="font-family:Menlo;margin:0px;line-height:normal"><span>    ...</span></div><div style="margin:0px;line-height:normal;font-family:Menlo">}</div></span></div></span></span></div><div><br></div><div>- Dave Sweeris</div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>