Move r-infix blanks to the macro itself.
This commit is contained in:
parent
b7d3022b77
commit
ddbb9971fd
@ -5,19 +5,19 @@
|
|||||||
(list (second form) (first form) (nth form 2)))
|
(list (second form) (first form) (nth form 2)))
|
||||||
|
|
||||||
(defmacro infix-better [form]
|
(defmacro infix-better [form]
|
||||||
`(~(second form)
|
`(~(second form) ; Note the syntax-quote (`) and unquote (~) characters!
|
||||||
__
|
__
|
||||||
__ ))
|
__ ))
|
||||||
|
|
||||||
(defmacro r-infix [form]
|
(defmacro r-infix [form]
|
||||||
(cond (not (seq? form))
|
(cond (not (seq? form))
|
||||||
form
|
__
|
||||||
(= 1 (count form))
|
(= 1 (count form))
|
||||||
`(r-infix ~(first form))
|
`(r-infix ~(first form))
|
||||||
:else
|
:else
|
||||||
(let [operator (second form)
|
(let [operator (second form)
|
||||||
first-arg (first form)
|
first-arg (first form)
|
||||||
others (drop 2 form)]
|
others __]
|
||||||
`(~operator
|
`(~operator
|
||||||
(r-infix ~first-arg)
|
(r-infix ~first-arg)
|
||||||
(r-infix ~others)))))
|
(r-infix ~others)))))
|
||||||
@ -40,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) + (4 * 5)))))
|
(= 36 (r-infix (10 + (2 * 3) + (4 * 5)))))
|
||||||
|
|
||||||
|
@ -136,12 +136,13 @@
|
|||||||
|
|
||||||
"macros" {"__" ['~(first form)
|
"macros" {"__" ['~(first form)
|
||||||
'~(nth form 2)
|
'~(nth form 2)
|
||||||
|
'form
|
||||||
|
'(drop 2 form)
|
||||||
"Hello, Macros!"
|
"Hello, Macros!"
|
||||||
10
|
10
|
||||||
''(+ 9 1)
|
''(+ 9 1)
|
||||||
''(* 10 2)
|
''(* 10 2)
|
||||||
''(+ 10 (2 * 3))
|
''(+ 10 (2 * 3))]}
|
||||||
36]}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
(defn replace-with [s k replacements]
|
(defn replace-with [s k replacements]
|
||||||
|
Loading…
Reference in New Issue
Block a user