From daa6443e7cec13167110a947076f0e8e90409526 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Tue, 12 Mar 2013 22:04:51 -0400 Subject: [PATCH] Adding in a Threading macro (->) --- hy/core/bootstrap.py | 12 ++++++++++++ tests/native_tests/language.hy | 5 +++++ 2 files changed, 17 insertions(+) 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"])))