|
|
|
@ -5,19 +5,19 @@
|
|
|
|
|
(list (second form) (first form) (nth form 2)))
|
|
|
|
|
|
|
|
|
|
(defmacro infix-better [form]
|
|
|
|
|
`(~(second form)
|
|
|
|
|
`(~(second form) ; Note the syntax-quote (`) and unquote (~) characters!
|
|
|
|
|
__
|
|
|
|
|
__ ))
|
|
|
|
|
|
|
|
|
|
(defmacro r-infix [form]
|
|
|
|
|
(cond (not (seq? form))
|
|
|
|
|
form
|
|
|
|
|
__
|
|
|
|
|
(= 1 (count form))
|
|
|
|
|
`(r-infix ~(first form))
|
|
|
|
|
:else
|
|
|
|
|
(let [operator (second form)
|
|
|
|
|
first-arg (first form)
|
|
|
|
|
others (drop 2 form)]
|
|
|
|
|
others __]
|
|
|
|
|
`(~operator
|
|
|
|
|
(r-infix ~first-arg)
|
|
|
|
|
(r-infix ~others)))))
|
|
|
|
@ -40,5 +40,5 @@
|
|
|
|
|
(= __ (macroexpand '(infix-better ( 10 + (2 * 3)))))
|
|
|
|
|
|
|
|
|
|
"Really, you dont understand recursion until you understand recursion"
|
|
|
|
|
(= __ (r-infix (10 + (2 * 3) + (4 * 5)))))
|
|
|
|
|
(= 36 (r-infix (10 + (2 * 3) + (4 * 5)))))
|
|
|
|
|
|
|
|
|
|