Skip to content

Instantly share code, notes, and snippets.

@kriyative
Created March 13, 2012 18:40
Show Gist options
  • Save kriyative/2030582 to your computer and use it in GitHub Desktop.
Save kriyative/2030582 to your computer and use it in GitHub Desktop.
Clojure `thrush` operator macro in Common Lisp
(defmacro -> (x &rest args)
"A Common-Lisp implementation of the Clojure `thrush` operator."
(destructuring-bind (form &rest more)
args
(cond
(more `(-> (-> ,x ,form) ,@more))
((and (consp form)
(or (eq (car form) 'lambda)
(eq (car form) 'function)))
`(funcall ,form ,x))
((consp form) `(,(car form) ,x ,@(cdr form)))
(form `(,form ,x))
(t x))))
#+test
(equal (-> 0
(lambda (x) (+ 1 x))
(cons 1)
(cons 2))
'((1 . 1) . 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment