Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
Well this still hasn't solved my problem. Because I shouldn't bind from left to right, but arbitrarily. So ideally I would want this: void foo(string str, int x, int y, string str2) { } alias bind!(foo, null, 1, 2, null) twoStrings; twoStrings("abc", "def"); -> foo("abc", 1, 2, "def"); I'm

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread bearophile
Andrej Mitrovic: > Maybe "bind" should be a better name. I'm not sure.. In Python there is something similar that's named "partial": http://docs.python.org/library/functools.html#functools.partial Bye, bearophile

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
On 4/6/11, bearophile wrote: > - Currying and partial function application are not exactly the same thing. > So I am not sure the "curry" in std.functional is named correctly; Maybe "bind" should be a better name. I'm not sure..

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
Wow, talk about enlightement. I think I've done it now: import std.stdio; import std.traits; import std.metastrings; template count(T...) { enum count = T.length; } template myCurry(alias fun, args...) { static if (args.length > (ParameterTypeTuple!fun).length) { static asser

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread bearophile
Andrej Mitrovic: > Here's a basic implementation: I have some general comments: - Currying and partial function application are not exactly the same thing. So I am not sure the "curry" in std.functional is named correctly; - Partial application is important in a language that wants to support f

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
It's still wrong, the tuple is backwards. Haha, that's what I get for not unittesting.

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
Ok, enjoy this monstrosity: template count(T...) { enum count = T.length; } template myCurry(alias fun, args...) { static if (args.length > (ParameterTypeTuple!fun).length) { static assert(0, Format!("Tried to pass %s arguments, max is %s.", co

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
Crap, that is a horrible implementation, I didn't take into account not binding all arguments. Be right back..

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
Here's a basic implementation: import std.stdio; import std.traits; import std.metastrings; template count(T...) { enum count = T.length; } template curry(alias fun, args...) { static if (args.length > (ParameterTypeTuple!fun).length) { static assert(0, Format!("Tried to pass

Re: Why doesn't curry work with multiple arguments?

2011-04-06 Thread Andrej Mitrovic
Andrej Mitrovic Wrote: > Yes, I write a whole new function, but why do that when curry is there. Or so > I thought.. Oops: *Yes, I _can_ write a whole new function