Impressed

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 27 12:30:23 PDT 2012


On Friday, July 27, 2012 21:22:47 Stuart wrote:
> On Friday, 27 July 2012 at 19:17:10 UTC, H. S. Teoh wrote:
> > Nevertheless, D has gotten to the point where it's powerful
> > enough that most feature requests can be implemented in a
> > library rather than as a language extension.
> 
> How could Yield be implemented as a library feature? Something
> like:
> 
>     return ITERATOR(
>        { ...setup code ... },
>        { ...loop body code... })
> 
> ?
> 
> I don't see how that would work. Variables declared in the setup
> would not be accessible from the body. I guess it could be done a
> bit like this:
> 
>     Enumerable!int ExampleFunction() {
>        ... create some variables ...
>        return ITERATOR!int( {
>           ...do something with variables...
>           ...return something...
>        } )
>     }
> 
> That the kind of thing you mean?

As they're delegates, you could just put any variables you need in both 
functions in surrounding function. So, something like that could be done, 
though it would probably be built around the idea that you'd be giving lambdas 
for empty, front, and popFront rather than an iterator.

But regardless, I'm sure that a library solution could be found, and at this 
point, unless a library solution really just doesn't work or is really ugly 
and the feature is really needed, it's not going to be added to the language. 
D is incredibly powerful, and there's been a large push (especially from 
Andrei) to use that power to solve problems rather than add more to the 
language to do it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list