diff options
-rw-r--r-- | lib.macros.lisp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib.macros.lisp b/lib.macros.lisp index 057a89f..5489564 100644 --- a/lib.macros.lisp +++ b/lib.macros.lisp @@ -19,7 +19,7 @@ (in-package :lib.macros) -(defmacro --> (&rest functions) +(defmacro --> (&rest forms) "Lexically bind current form as `_' for use in the next form, returning the result of the last form. @@ -34,30 +34,29 @@ i.e. Also includes transformer where symbols are considered unary functions i.e. (--> x y) <-> (--> x (y _)). " - (if (null functions) + (if (null forms) nil (let ((assignment-forms - (loop :for f :in functions + (loop :for f :in forms :for canon-f = (if (symbolp f) (list f 'lib.macros:_) f) :collect `(lib.macros:_ ,canon-f)))) `(let* ,assignment-forms lib.macros:_)))) -(defmacro ->> (&rest functions) +(defmacro ->> (&rest forms) "Make current form the last argument of the next form, returning the last form. i.e. (->> (a1 a2...) (b1 b2...) (c1 c2...)) == (c1 c2 ... (b1 b2 ... (a1 a2 ...))) -Also includes transformer where fun in functions that are symbols are considered -unary functions. +Also includes transformer where symbols are considered unary functions. Like the `|>' operator in Ocaml." - (if (null functions) + (if (null forms) nil - (loop :with acc = (car functions) - :for func :in (cdr functions) + (loop :with acc = (car forms) + :for func :in (cdr forms) :for canon-func = (if (symbolp func) (list func) func) :do (setq acc (append canon-func (list acc))) :finally (return acc)))) |