Impressed
Dmitry Olshansky
dmitry.olsh at gmail.com
Fri Jul 27 09:28:35 PDT 2012
On 27-Jul-12 20:15, Jesse Phillips 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.
>
> You wouldn't use map for that, that would be silly.
>
> Taking a look at DirIteratorImpl[1] in std.file suggest there is a lot
> of setup to navigate the filesystem on Windows. How does Yield help with
> that logic?
>
It should be more straightforward as DirIteratorImpl does maintain stack
of directories/searches as it goes.
The yield version could simply use recursion and yield a-la opApply
version that was there before.
But this advantage is unimportant since arbitrary deep recursion is a
security risk (especially for servers that typically use threads with
tiny stacks).
> 1.
> https://github.com/D-Programming-Language/phobos/blob/master/std/file.d#L2397
>
>
> Seriously I'll take my composing ranges over iterators any day.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list