On 3/8/2014 5:58 PM, Piotr Szturmaj wrote:
W dniu 2014-03-08 02:09, H. S. Teoh pisze:
Having a way to auto-generate input range boilerplate, though, would be
really, *really* nice. Coroutine-style code would be ideal.

https://github.com/pszturmaj/dgenerators

Yea, there is that approach, which is nice in certain ways. I did the same kinda thing a couple years ago[1], but your API appears much, much nicer.

The unfortunate downside, though, is that as jerro demonstrated[2] there's a high overhead when using fibers for iteration. It likely wouldn't be an issue for some things, like IO, but for other things it could be a problem.

So what we end up with is an unfortunate three-way choice anytime someone needs a generator in D:

1. Give up on range compatibility (opApply)
2. Give up on straightforward implementation (input/forward range)
3. Give up on maximum performance (fiber-based coroutine range)

D's just dancing all around the ideal solution for generators without ever actually hitting the mark. Which I find frustrating because I know that's a target D's capable of nailing.

[1] http://semitwist.com/articles/article/view/combine-coroutines-and-input-ranges-for-dead-simple-d-iteration

[2] http://forum.dlang.org/thread/jno6o5$qtb$1...@digitalmars.com

Reply via email to