Skip to content

Instantly share code, notes, and snippets.

@joaofnds
Last active October 20, 2019 14:30
Show Gist options
  • Save joaofnds/950bbf4d088b470294ac02fd0f2d8395 to your computer and use it in GitHub Desktop.
Save joaofnds/950bbf4d088b470294ac02fd0f2d8395 to your computer and use it in GitHub Desktop.
Naive implementation of a "pipe" macro (does *not* support lambdas)
(defmacro -> (args &body forms)
(flet ((ensure-list (arg) (if (listp arg) arg (list arg))))
(reduce
(lambda (args f)
(ensure-list
(case (type-of f)
(function (apply f args))
(symbol (apply f args))
(cons (apply (car f) (append (cdr f) args))))))
forms
:initial-value (ensure-list args))))
(-> 1
(+ 1)
1+
(* 2)
(format t "result is: ~a~%")) ; #=> result is: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment