Suppose you have three arity functions 1, 2, and 3, as shown below:
(defn I [x] x)
(defn K [x y] x)
(defn S [x y z] (x z (y z)))
Does clojure have an evaluation function or idiom to evaluate:
(I K S I I) as (I (K (S (I (I)))))
returning arity 2 parity function?
I am considering creating a macro that can take simple definitions of functions above and extend them to ambiguity functions that can return partial results. I would not want to create a macro if there is already a built-in or idiomatic way to accomplish this.
Here's what we would like for advanced macros for the above functions:
(defn I
([x] I x)
([x & more] (apply (I x) more)))
(defn K
([x] (partial K x))
([x y] x)
([x y & more] (apply (K x y) more)))
(defn S
([x] (partial S x))
([x y] (partial S x y))
([x y z] (x z (y z)))
([x y z & more] (apply (S x y z) more)))
source
share