Jun. 27th, 2012

l33tminion: (Skilled)
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))))))
Page generated Jul. 9th, 2025 04:06 pm
Powered by Dreamwidth Studios