From a94831beac96be072b1ce70f94ebee09676d88e1 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Mon, 18 Mar 2013 21:46:58 -0400 Subject: [PATCH] add mod operator --- hy/compiler.py | 4 +++- tests/native_tests/math.hy | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hy/compiler.py b/hy/compiler.py index bad6434..4852d7e 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -341,6 +341,7 @@ class HyASTCompiler(object): col_offset=e.start_column) @builds("+") + @builds("%") @builds("-") @builds("/") @builds("*") @@ -352,7 +353,8 @@ class HyASTCompiler(object): ops = {"+": ast.Add, "/": ast.Div, "*": ast.Mult, - "-": ast.Sub} + "-": ast.Sub, + "%": ast.Mod} inv = expression.pop(0) op = ops[inv] diff --git a/tests/native_tests/math.hy b/tests/native_tests/math.hy index a593ea3..6172972 100644 --- a/tests/native_tests/math.hy +++ b/tests/native_tests/math.hy @@ -28,3 +28,7 @@ (def test_div (fn [] "NATIVE: Test division" (assert (= 25 (/ 100 2 2))))) + +(defn test-modulo [] + "NATIVE: test mod" + (assert (= (% 10 2) 0)))