stugol at gmx.com
Fri Jul 27 11:47:32 PDT 2012
On Friday, 27 July 2012 at 15:09:38 UTC, Graham Fawcett wrote:
> On Friday, 27 July 2012 at 13:10:46 UTC, Stuart wrote:
>> On Friday, 27 July 2012 at 03:00:25 UTC, Brad Anderson wrote:
>>> D equivalent: iota(0, int.max, 2).map!(a => /* do something
>>> with even numbers */)();
>> I think you're missing the point. The purpose isn't to
>> generate a sequence of numbers, but to illustrate how the
>> Yield keyword is used in VB.NET. Sure, getting a sequence of
>> numbers may be straightforward, but what about a
>> lazy-populated list of all files on a computer? That can be
>> done using Yield - and more importantly, WRITTEN like a normal
>> synchronous function. Let's see you do that with map.
> That's easy:
> [...elided code...]
> auto entries = dirEntries(BASE_DIR, SpanMode.breadth);
Ah, but that depends upon the pre-existence of the dirEntries()
function. I think perhaps you're missing the point - which is
that "Yield" allows you to WRITE a function synchronously which
will then be executed lazily, as an iterator. What you have
demonstrated there is USING a lazy function. How would I write,
in D, a function that would lazily assemble some data and return
it as a lazy collection? I mean, without calling existing lazy
Unless ranges (which I admit to knowing very little about) can do
this, I respectfully request that Yield be supported in D.
> You should spend some time using ranges before drawing
> conclusions about them.
Is there a good tutorial on them? I didn't see one on the website.
More information about the Digitalmars-d