Can clojure evaluate a function chain of a mixed function and return a partial function if necessary?

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)))
+5
source share
1 answer

, , , comp " " , . :

user> ((comp vec rest list) 1 2 3 4 5)
=> [2 3 4 5]

:

user> (vec (rest (list 1 2 3 4 5)))
=> [2 3 4 5]

, (I K S I I), (I (K (S (I (I))))), (reduce comp ...), (apply comp ...).

user> ((reduce comp [vec rest list]) 1 2 3 4 5)
=> [2 3 4 5]
user> ((apply comp [vec rest list]) 1 2 3 4 5)
=> [2 3 4 5]

-> ->>. . -> , ->> . " " - , (function nested-things-so-far) .

, :

(-> 1 (+ 10) (- 100) inc)
;//Expands to...
(inc (- (+ 1 10) 100))
;//Evaluating in the REPL...
user> (-> 1 (+ 10) (- 100) inc)
=> -88

(->> 1 (+ 10) (- 100) inc)
;//Expands to...
(inc (- 100 (+ 10 1)))
;//Evaluating in the REPL...
user> (-> 1 (+ 10) (- 100) inc)
=> 90

, , -, - (, , , ), .

+5

All Articles