[plt-scheme] Why do layman programmers care about Currying?
2008/12/30 Grant Rettke <grettke at acm.org>:
> Why do layman (working programmers) care about Currying? Or how are
> they applied in daily use to help one out?
>
> http://en.wikipedia.org/wiki/Currying
I find currying is useful as an alternative of (or at least
alternative syntax for) small anonymous lambdas. This gets used more
often in Haskel, but digging through some Scheme code I wrote for a
compiler design class, here's a really simple example.
; process a class definition
(define (process-class class)
(for-each (curry process-function class) (defn:class-methods class)))
This code in particular traverses a class definition from the parse
tree, with the eventual aim of filling in things like labels to use
for function addresses in the generated assembly. Here
process-function needs the class definition as context for function
processing, so I provide it as the first argument. Using curry just
gives me a convenient way to fix the first argument. I could have used
(lambda (f) (process-function class f)), but I find curry clearer.
Also, lambda expressions like that one are less practical for
functions which take more arguments, or even keyword arguments.
But this is just my use, maybe someone else can come up with something
more interesting. =)
Henk