Sam (
l33tminion) wrote2012-06-27 04:33 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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:
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))))))