[plt-scheme] Currying functions?
I was just browsing the language manual and came across an
interesting function: procedure-arity. Now, it just happens that
yesterday I had occasion to want to create a curried version of a
binary operator (as part of the evaluator I'm working on, where I
wanted to map it across an argument list), so I searched for curry
and currying in Help Desk and found nothing. Well, in the case of
functions of arity 2 it's easy:
> (define (curry2 f)
(lambda (x)
(lambda (y)
(f x y))))
> (define a (curry2 +))
> ((a 2) 3)
5
but to create a curried version of an arbitrary function, you need to
know it's arity. Maybe it's possible to create a curried version of a
function taking a variable number of arguments, but I'm not sure how
it would be done.
===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net
"The universe is not required to be in
perfect harmony with human ambition."
--Carl Sagan