diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-19 07:18:52 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-19 07:19:51 +0000 |
commit | cc53e6ec42316262e9ad87230cb6892949d7a42b (patch) | |
tree | 120bd9489b27d1022d7d97e1d8160478f23c639a /lib/macros.lisp | |
parent | 87554dcc3a4ecf6dbe4f44496b6a0bb0c2252a68 (diff) | |
download | cantedraw-cc53e6ec42316262e9ad87230cb6892949d7a42b.tar.gz cantedraw-cc53e6ec42316262e9ad87230cb6892949d7a42b.tar.bz2 cantedraw-cc53e6ec42316262e9ad87230cb6892949d7a42b.zip |
Implement -<> operator for threading an argument through first parameter
Diffstat (limited to 'lib/macros.lisp')
-rw-r--r-- | lib/macros.lisp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/macros.lisp b/lib/macros.lisp index cb11901..e82d566 100644 --- a/lib/macros.lisp +++ b/lib/macros.lisp @@ -63,6 +63,26 @@ Like the `|>' operator in Ocaml." :do (setq acc (append canon-func (list acc))) :finally (return acc)))) + +(defmacro -<> (&rest forms) + "Make current form the first argument of the next form, returning the last + form. + +i.e. +(-<> (a1 a2...) (b1 b2...) (c1 c2...)) == (c1 (b1 (a1 a2 ...) b2 ...) c2 ...) + +Also includes transformer where symbols are considered unary functions. + +Like the `|>' operator in Ocaml." + (if (null forms) + nil + (loop :with acc = (car forms) + :for func :in (cdr forms) + :for canon-func = (if (symbolp func) (list func) func) + :do (push acc (cdr canon-func)) + :do (setq acc canon-func) + :finally (return acc)))) + (defmacro while (condition &body body) `(loop :while ,condition :do |