D component programming is a joke (Was: Re: Component programming)
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Aug 3 11:01:01 PDT 2013
On Fri, Aug 02, 2013 at 06:07:02PM -0700, Andrei Alexandrescu wrote:
> On 2013-08-02 23:27:20 +0000, Timon Gehr said:
> >Also, you may want to replace some of the manually implemented
> >ranges where this makes sense.
> >
> >Eg, datesInYear can be expressed more to the point as:
> >
> >
> >auto datesInYear(int year){
> > return Date(year,1,1).recurrence!((a,n)=>a[n-1]+1.dur!"days")
> > .until!(a=>a.year>year);
> >}
> >
> >(This closes over year though. The following version uses only
> >closed lambdas by embedding year in the returned range object:
> >
> >
> >auto datesInYear(int year){
> > return Date(year,1,1)
> > .recurrence!((a,n)=>a[n-1]+1.dur!"days")
> > .zip(year.repeat)
> > .until!(a=>a[0].year>a[1]).map!(a=>a[0]);
> >})
Thanks! I replaced the code with the first version above. I decided that
it's OK to close over year; it's a good example of the convenience of D
closures. And I also don't feel like explaining the functional
gymnastics of using zip and map just to avoid a closure. :)
> Would be nice to have a couple of these both explicit and also
> implemented with the stdlib.
[...]
I felt the article was approaching the long side, so I decided to just
use Timon's simplified code instead of the original explicit
implementation.
Or do you think it's better to have both, for comparison?
T
--
Ignorance is bliss... but only until you suffer the consequences!
More information about the Digitalmars-d
mailing list