Fiddling with the threading macro

This commit is contained in:
Paul Tagliamonte 2013-03-13 09:03:50 -04:00
parent 8cf9bd582d
commit 57775a95a6
2 changed files with 13 additions and 5 deletions

View File

@ -49,11 +49,13 @@ def cond_macro(tree):
@macro("_>")
def threading_macro(tree):
tree.pop(0) # ->
tree.reverse()
tree.pop(0)
ret = tree.pop(0)
root = ret
for node in tree:
ret.insert(1, node)
if not isinstance(node, HyExpression):
nnode = HyExpression([node])
nnode.replace(node)
node = nnode
node.insert(1, ret)
ret = node
return root
return ret

View File

@ -139,6 +139,12 @@
["X" "B" "C" "D"])))
(defn test-threading-two []
"NATIVE: test threading macro"
(assert (= (-> "a b c d" .upper (.replace "A" "X") .split)
["X" "B" "C" "D"])))
(defn test-assoc []
"NATIVE: test assoc"
(def vals {"one" "two"})