diff --git a/hy/compiler.py b/hy/compiler.py index 74a0fbf..cf156b2 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -812,7 +812,6 @@ class HyASTCompiler(object): @builds("+") @builds("%") - @builds("-") @builds("/") @builds("//") @builds("*") @@ -851,6 +850,18 @@ class HyASTCompiler(object): left = calc return calc + @builds("-") + @checkargs(min=1) + def compile_maths_expression_sub(self, expression): + if len(expression) > 2: + return self.compile_maths_expression(expression) + else: + arg = expression[1] + return ast.UnaryOp(op=ast.USub(), + operand=self.compile(arg), + lineno=arg.start_line, + col_offset=arg.start_column) + @builds("+=") @builds("/=") @builds("//=") diff --git a/tests/native_tests/math.hy b/tests/native_tests/math.hy index 471e8e4..107f9f5 100644 --- a/tests/native_tests/math.hy +++ b/tests/native_tests/math.hy @@ -17,7 +17,8 @@ (setv test_sub (fn [] "NATIVE: Test subtraction" - (assert (= 4 (- 8 4))))) + (assert (= 4 (- 8 4))) + (assert (= -8 (- 8))))) (setv test_add (fn []