Use case for std.bind
Jason House
jason.james.house at gmail.com
Wed Feb 25 05:54:12 PST 2009
Andrei Alexandrescu Wrote:
> Daniel Keep wrote:
> > The problem I have with these suggestions are that you're basically
> > arguing for an incredibly inflexible, context-dependant, completely
> > unintuitive syntax for something you already have working syntax for. I
> > just don't see the point.
>
> I'd agree that generally there's a strong bias in this group for adding
> to the language. Every itsy-bitsy issue comes around, there are a dozen
> cute syntaxes invented for it right on the spot. And then once every few
> months, there's the inevitable huge thread "Where did my simple language
> go???" :o)
>
> Currying/binding can be done easily with a library, and the
> implementation is so simple there's no need for a separate file
> dedicated to it. The one interesting case is currying a function passed
> by alias. In that case there's no indirect call, just a little struct
> created that contains the curried state:
>
> int plus(int x, int y} { return x + y; }
> auto plus5 = curry!(plus)(5);
> assert(plus5(10) == 15);
>
> typeof(plus5) will be a little struct that may be cumbersome to pass
> around, in which case you do want to take the toll of the indirect call
> by writing:
>
> auto plus5 = makeDelegate(curry!(plus)(5));
> assert(is(typeof(plus5) == int delegate(int));
> assert(plus5(10) == 15);
>
> This stuff belongs to std.functional. I plan to eliminate std.bind and
> put currying and binding in std.functional. What do people think?
>
> Andrei
I've done the whole boost::bind thing before and it sucks. When boost::lambda came out, that was way better. Anonymous delegates are even better. Learning a separate functional syntax will always be a sub par solution to me.
I'll go even further. If D had only what you've proposed for ranges and std.functional but lacked opApply and anonymous delegates, I never would have become a D user. Simple, clean syntax is that important to me... Please don't recreate boost and STL in D. They're great libraries, but we can do way better than that!
More information about the Digitalmars-d
mailing list