Tweak wording very slightly for new macros koans.
This commit is contained in:
parent
08415ecb94
commit
bc9113fe60
@ -1,18 +1,14 @@
|
|||||||
"Macros are also just functions!"
|
|
||||||
(defmacro hello [x]
|
(defmacro hello [x]
|
||||||
(str "Hello, " x))
|
(str "Hello, " x))
|
||||||
|
|
||||||
"Create a list and use it to be eval-ed at run time"
|
|
||||||
(defmacro infix [form]
|
(defmacro infix [form]
|
||||||
(list (second form) (first form) (nth form 2)))
|
(list (second form) (first form) (nth form 2)))
|
||||||
|
|
||||||
"Sometimes it is easier to handcraft it ..."
|
|
||||||
(defmacro infix-better [form]
|
(defmacro infix-better [form]
|
||||||
`(~(second form)
|
`(~(second form)
|
||||||
__
|
__
|
||||||
__ ))
|
__ ))
|
||||||
|
|
||||||
"Macro in a macro until you get a stack overflow! ;)"
|
|
||||||
(defmacro r-infix [form]
|
(defmacro r-infix [form]
|
||||||
(list (second form)
|
(list (second form)
|
||||||
(if (instance? clojure.lang.PersistentList (first form))
|
(if (instance? clojure.lang.PersistentList (first form))
|
||||||
@ -25,23 +21,21 @@
|
|||||||
|
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
"Macros are just function eval-ed at compile time"
|
"Macros are like functions created at compile time"
|
||||||
(= "Hello, Macros!" (hello "Macros!"))
|
(= __ (hello "Macros!"))
|
||||||
|
|
||||||
"Can I haz some infix?"
|
"Can I haz some infix?"
|
||||||
(= __ (infix (9 + 1)))
|
(= __ (infix (9 + 1)))
|
||||||
|
|
||||||
"Remember these are nothing but code transformations"
|
"Remember, these are nothing but code transformations"
|
||||||
(= __ (macroexpand '(infix (9 + 1))))
|
(= __ (macroexpand '(infix (9 + 1))))
|
||||||
|
|
||||||
"You can do better than that, hand crafting ftw"
|
"You can do better than that, hand crafting ftw!"
|
||||||
(= __ (macroexpand '(infix-better (10 * 2))))
|
(= __ (macroexpand '(infix-better (10 * 2))))
|
||||||
|
|
||||||
"Things dont always work as you would like them to... "
|
"Things dont always work as you would like them to... "
|
||||||
(= __ (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)))))
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@ -135,14 +135,13 @@
|
|||||||
'(fn [x] (+ 20 x))]}
|
'(fn [x] (+ 20 x))]}
|
||||||
|
|
||||||
"macros" {"__" ['~(first form)
|
"macros" {"__" ['~(first form)
|
||||||
'~(nth form 2)
|
'~(nth form 2)
|
||||||
10
|
"Hello, Macros!"
|
||||||
''(+ 9 1)
|
10
|
||||||
''(* 10 2)
|
''(+ 9 1)
|
||||||
''(+ 10 (2 * 3))
|
''(* 10 2)
|
||||||
16
|
''(+ 10 (2 * 3))
|
||||||
]
|
16]}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
(defn replace-with [s k replacements]
|
(defn replace-with [s k replacements]
|
||||||
|
Loading…
Reference in New Issue
Block a user