Use case for std.bind

Yigal Chripun dude at sweet.com
Tue Feb 24 10:34:30 PST 2009


Andrei Alexandrescu Wrote:
> 
> 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)

I disagree with this notion. there are requests to add new *useful* features but there are also requests to remove unneeded features, latest was the discussion of the implicit concatenation of string literals. There was a thread not long ago listing the features most people want to remove - foreach_reverse comes to mind.  
that how evolution works - you add new useful stuff and remove old unneeded baggage.  both are equally important. 

> 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 



More information about the Digitalmars-d mailing list