Fiddling with the threading macro
This commit is contained in:
parent
8cf9bd582d
commit
57775a95a6
@ -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
|
||||
|
@ -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"})
|
||||
|
Loading…
x
Reference in New Issue
Block a user