Function Currying
Hasan Aljudy
hasan.aljudy at gmail.com
Tue Nov 14 21:28:18 PST 2006
Walter Bright wrote:
> Hasan Aljudy wrote:
>>
>>
>> Brad Roberts wrote:
>>> The net is a truly wonderful resource:
>>>
>>> http://en.wikipedia.org/wiki/Curried_function
>>
>> I've read that a while ago, but it doesn't make much of a sense. Why
>> would anyone need such a thing?
>> My original question was, is it something that everyone is supposed to
>> already know its meaning and uses?
>
> It's handy when you want to 'save' a command for future use, such as
> pushing it onto an undo/redo stack. Being able to encapsulate the
> arguments into just a function call make this particularly useful.
Hmm, sounds legitimate but I still don't quiet get it. Can you give a
more concrete example?
I mean, I can always save a command using a nested function. Why would I
choose to call a curry template for something like, say:
void func( type arg )
{
doSomething(arg);
......
doSomething(arg);
..
doSomething(arg);
..
doSomething(arg);
//I'm tired of this ..
//call nested functions to the rescue ..
void doit()
{
doSomething(arg);
}
doit();
doit();
...
doit();
}
I'm more confident using a nested function, at least I know what's going
on. With a curried function, I'd be more like "gee I'm not sure what's
going on but I hope this works ..".
More information about the Digitalmars-d
mailing list