Function Currying
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Nov 14 21:36:20 PST 2006
"Hasan Aljudy" <hasan.aljudy at gmail.com> wrote in message
news:eje8hg$10on$1 at digitaldaemon.com...
>
> 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 ..".
Go ahead and try to return doit() from func(), or save it somewhere where it
will be accessed after func() returns ;) I mean, you _could_ do it without
templates using a struct as the context (much as Walter's posted code does),
but you'd be seriously restricting yourself to functions/delegates with
certain signatures.
More information about the Digitalmars-d
mailing list