macros: add comp

This commit is contained in:
hellerve 2019-11-29 15:25:27 +01:00
parent bd397f8d50
commit 65db2bc2a8

View File

@ -372,3 +372,13 @@ The expression must be evaluable at compile time.")
(list 'if (list 'defined? var)
()
(list 'defdynamic var expr)))
(defndynamic comp-internal [sym fns]
(if (= (length fns) 0)
sym
(list (car fns) (comp-internal sym (cdr fns)))))
(doc comp "composes the functions `fns` into one `fn`.")
(defmacro comp [:rest fns]
(let [x (gensym)]
(list 'fn [x] (comp-internal x fns))))