diff --git a/hy/core/bootstrap.py b/hy/core/bootstrap.py index 2e7dd3d..18f4cd5 100644 --- a/hy/core/bootstrap.py +++ b/hy/core/bootstrap.py @@ -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 diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 9c079f4..1d78333 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -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"])))