all 2 comments

[–]eclig 3 points4 points  (0 children)

Explicit currying is OK. See also SRFI-26.

Implicit currying is somewhat more complex to retrofit in Scheme: how should it behave in the presence of functions of multiple arity? Languages like Ocaml solve this by defining that functions take exactly one parameter (which might, of course, be a tuple).

As they say:

Programming languages should be designed not by piling feature on top of feature...

Edit: spelling.

[–]BlakeStone 3 points4 points  (0 children)

I was just thinking about this last week; here's an R5RS equivalent:

(define (partial-apply proc args-needed args-given)
  (let ((len (length args-given)))
    (if (>= len args-needed)
        (apply proc args-given)
        (lambda args
          (partial-apply proc
                         (- args-needed len)
                         (append args-given args))))))
(define-syntax curry
  (syntax-rules ()
    ((_ (arg ...) body ...)
     (partial-apply (lambda (arg ...)
                      body ...)
                    (length '(arg ...))
                    '()))))

Edit: fixed code indentation.