Allow r-infix to work with more than 2 operands.
This commit is contained in:
parent
3e4d2caebf
commit
b7d3022b77
@ -10,14 +10,17 @@
|
|||||||
__ ))
|
__ ))
|
||||||
|
|
||||||
(defmacro r-infix [form]
|
(defmacro r-infix [form]
|
||||||
(list (second form)
|
(cond (not (seq? form))
|
||||||
(if (instance? clojure.lang.PersistentList (first form))
|
form
|
||||||
`(r-infix ~(first form))
|
(= 1 (count form))
|
||||||
(first form))
|
`(r-infix ~(first form))
|
||||||
(if (instance? clojure.lang.PersistentList (nth form 2))
|
:else
|
||||||
`(r-infix ~(nth form 2))
|
(let [operator (second form)
|
||||||
(nth form 2))
|
first-arg (first form)
|
||||||
))
|
others (drop 2 form)]
|
||||||
|
`(~operator
|
||||||
|
(r-infix ~first-arg)
|
||||||
|
(r-infix ~others)))))
|
||||||
|
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
@ -37,5 +40,5 @@
|
|||||||
(= __ (macroexpand '(infix-better ( 10 + (2 * 3)))))
|
(= __ (macroexpand '(infix-better ( 10 + (2 * 3)))))
|
||||||
|
|
||||||
"Really, you dont understand recursion until you understand recursion"
|
"Really, you dont understand recursion until you understand recursion"
|
||||||
(= __ (r-infix (10 + (2 * 3)))))
|
(= __ (r-infix (10 + (2 * 3) + (4 * 5)))))
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@
|
|||||||
''(+ 9 1)
|
''(+ 9 1)
|
||||||
''(* 10 2)
|
''(* 10 2)
|
||||||
''(+ 10 (2 * 3))
|
''(+ 10 (2 * 3))
|
||||||
16]}
|
36]}
|
||||||
})
|
})
|
||||||
|
|
||||||
(defn replace-with [s k replacements]
|
(defn replace-with [s k replacements]
|
||||||
|
Loading…
Reference in New Issue
Block a user