l33tminion: (Skilled)
Sam ([personal profile] l33tminion) wrote2012-06-27 04:33 pm
Entry tags:

Math With More Curry

A StackOverflow poster asked if auto-currying functions could be implemented in Lisp dialects, and I decided to take a crack at it in Common Lisp.

Currying is easy enough to implement in Common Lisp, as shown here:
(defun curry (function &rest args)
  (lambda (&rest more-args)
    (apply function (append args more-args))))
But I found my (hopefully correct) implementation of auto-currying rather amusingly self-referential:
(defun auto-curry (function num-args)
  (lambda (&rest args)
    (if (>= (length args) num-args)
        (apply function args)
        (auto-curry (apply (curry #'curry function) args)
                    (- num-args (length args))))))

Post a comment in response:

(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org