Move r-infix blanks to the macro itself.

master
Colin Jones 13 years ago
parent b7d3022b77
commit ddbb9971fd

@ -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)))))

@ -136,12 +136,13 @@
"macros" {"__" ['~(first form)
'~(nth form 2)
'form
'(drop 2 form)
"Hello, Macros!"
10
''(+ 9 1)
''(* 10 2)
''(+ 10 (2 * 3))
36]}
''(+ 10 (2 * 3))]}
})
(defn replace-with [s k replacements]

Loading…
Cancel
Save