Sam (l33tminion) wrote,
  • Mood:

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))))))
Tags: math, programming
  • Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments