Adding in a Threading macro (->)

This commit is contained in:
Paul R. Tagliamonte 2013-03-12 22:04:51 -04:00
parent d68c1149e2
commit daa6443e7c
2 changed files with 17 additions and 0 deletions

View File

@ -45,3 +45,15 @@ def cond_macro(tree):
ret = n
return root
@macro("_>")
def threading_macro(tree):
tree.pop(0) # ->
tree.reverse()
ret = tree.pop(0)
root = ret
for node in tree:
ret.insert(1, node)
ret = node
return root

View File

@ -131,3 +131,8 @@
(def foo "3")
(assert (= *foo* FOO))
(assert (!= *foo* foo)))
(defn test-threading []
"NATIVE: test threading macro"
(assert (= (-> (.upper "a b c d") (.replace "A" "X") (.split))
["X" "B" "C" "D"])))