Move r-infix blanks to the macro itself.

This commit is contained in:
Colin Jones 2011-02-08 07:51:41 -06:00
parent b7d3022b77
commit ddbb9971fd
2 changed files with 7 additions and 6 deletions

View File

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

View File

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