Skip to content

Instantly share code, notes, and snippets.

@spacebat
Last active September 27, 2016 07:41
Show Gist options
  • Save spacebat/a54cd2f90463a09b70d75da5df47df53 to your computer and use it in GitHub Desktop.
Save spacebat/a54cd2f90463a09b70d75da5df47df53 to your computer and use it in GitHub Desktop.
Curry with uncurry in common lisp
(defvar *uncurry* nil "When bound and non-nil, curried functions can be uncurried")
(makunbound '*uncurry*)
(defun curry (function &rest args)
(lambda (&rest more-args)
(if (and (boundp '*uncurry*) *uncurry*)
(if more-args
(error "No more args expected")
function)
(apply function (append args more-args)))))
(defun uncurry (function)
(let ((*uncurry* t))
(funcall function)))
(funcall (curry '+ 1) 2)
;; 3
(uncurry (curry '+ 1))
;; +
(uncurry (curry (lambda (x) (+ 1 x)) 1))
;; #<anonymous interpreted function 4050012934>
(funcall (uncurry (curry (lambda (x) (+ 1 x)) 1)) 2)
;; 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment