On Thu, Jul 26, 2012 at 7:56 PM, Stuart <span dir="ltr"><<a href="mailto:stugol@gmx.com" target="_blank">stugol@gmx.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Friday, 27 July 2012 at 00:10:31 UTC, Brad Anderson wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
D uses ranges instead of iterators. You can read more about them here: <a href="http://ddili.org/ders/d.en/ranges.html" target="_blank">http://ddili.org/ders/d.en/<u></u>ranges.html</a><br>
<br>
I find ranges to be a vast improvement over iterators personally (I use iterators extensively in C++ for my job and lament not having ranges regularly).<br>
<br>
<br>
</blockquote></div><div class="im">
On Friday, 27 July 2012 at 00:17:21 UTC, H. S. Teoh wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
D has something far superior: ranges.<br>
<br>
        <a href="http://www.informit.com/articles/printerfriendly.aspx?p=1407357&rll=1" target="_blank">http://www.informit.com/<u></u>articles/printerfriendly.aspx?<u></u>p=1407357&rll=1</a><br>
<br>
Even better, they are completely implemented in the library. No<br>
unnecessary language bloat just to support them.<br>
</blockquote>
<br></div>
I'm not very well up on ranges. I understand the general [1 ... 6] type of ranges, but I really don't see how custom range functions could be as useful as the Yield support in <a href="http://VB.NET" target="_blank">VB.NET</a>. I mean, here's an example of an iterator in <a href="http://VB.NET" target="_blank">VB.NET</a>:<br>

<br>
   Public Function InfiniteSequence(StartValue As Int32, Step As Int32) As IEnumerable(Of Int32)<br>
      Do<br>
         Yield StartValue<br>
         StartValue += Step<br>
      Loop<br>
   End Function<br>
<br>
Usage:<br>
<br>
   For Each N in InfiniteSequence(2, 2)<br>
      ... do something with this sequence of even numbers ...<br>
   Next<br>
<br>
Notice how this function is written like a synchronous loop, yet yields a lazy-initialised infinite sequence of numbers. Granted, it's not a particularly useful example, but trust me: Iterators and Yield in .NET is *really* damn useful. I would go so far as to say it was one of the language's best features.<br>

<br>
I may be wrong, but it looks like I'd have to code a new class - not to mention several specific functions and some kind of state variable - just to simulate this functionality in D. Can anyone clarify this for me?<br>

</blockquote></div><br><div>D equivalent: iota(0, int.max, 2).map!(a => /* do something with even numbers */)();</div>