Last active
October 20, 2019 14:30
-
-
Save joaofnds/950bbf4d088b470294ac02fd0f2d8395 to your computer and use it in GitHub Desktop.
Naive implementation of a "pipe" macro (does *not* support lambdas)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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