[plt-scheme] Currying functions?

From: Bill Wood (william.wood3 at comcast.net)
Date: Sat Feb 4 18:56:31 EST 2006

On Sat, 2006-02-04 at 16:53 -0500, Eli Barzilay wrote:
   . . .
>   (curry +) == +
>   (curry + 1) == (lambda xs (apply + 1 xs))
>   (curry + 1 2) == (lambda xs (apply + 1 2 xs))
> 
> and you can use multiple `curry's to add more levels.  This seems like
> the only reasonable approach for arity-at-least-0 functions.

SRFI 26 seems not to compare too badly:

> (require (lib "cut.ss" "srfi" "26"))
> ((cut + <...>) 1 2 3 4)
10
> ((cut + 1 <...>) 2 3 4)
10
> ((cut + 1 2 <...>) 3 4)
10
> (letrec ((foo (lambda xs
                  (if (null? (cdr xs))
                      (printf "~A~N" (car xs))
                      (begin (printf "~A, " (car xs))
                             (apply foo (cdr xs)))))))
    ((cut foo 1 <> 3 <...>) 2 4))
1, 2, 3, 4

At least, it's a point in the design space.

 -- Bill Wood




Posted on the users mailing list.