Skip to content

Commit

Permalink
Adding in a Threading macro (->)
Browse files Browse the repository at this point in the history
  • Loading branch information
paultag committed Mar 13, 2013
1 parent d68c114 commit daa6443
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hy/core/bootstrap.py
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tests/native_tests/language.hy
Expand Up @@ -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"])))

0 comments on commit daa6443

Please sign in to comment.