diff --git a/hy/core/shadow.hy b/hy/core/shadow.hy index f59f0ca..e68c4ec 100644 --- a/hy/core/shadow.hy +++ b/hy/core/shadow.hy @@ -26,9 +26,12 @@ (defn + [&rest args] "Shadow + operator for when we need to import / map it against something" - (if (= (len args) 0) - 0 - (sum args))) ; shortcut here. + (let [[count (len args)]] + (if (zero? count) + (raise (TypeError "Need at least 1 argument to add/concatenate")) + (if (= count 1) + (get args 0) + (reduce operator.add args))))) (defn - [&rest args] diff --git a/tests/__init__.py b/tests/__init__.py index 56ab9fc..eb292ac 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,6 +12,7 @@ from .native_tests.when import * # noqa from .native_tests.with_decorator import * # noqa from .native_tests.core import * # noqa from .native_tests.reader_macros import * # noqa +from .native_tests.shadow import * # noqa from .native_tests.with_test import * # noqa from .native_tests.contrib.anaphoric import * # noqa from .native_tests.contrib.loop import * # noqa diff --git a/tests/native_tests/shadow.hy b/tests/native_tests/shadow.hy index 362ac50..54bf81e 100644 --- a/tests/native_tests/shadow.hy +++ b/tests/native_tests/shadow.hy @@ -1,11 +1,22 @@ - - (defn test-shadow-addition [] "NATIVE: test shadow addition" (let [[x +]] - (assert (= (x) 0)) + (assert (try + (x) + (catch [TypeError] True) + (else (throw AssertionError)))) (assert (= (x 1 2 3 4) 10)) - (assert (= (x 1 2 3 4 5) 15)))) + (assert (= (x 1 2 3 4 5) 15)) + ; with strings + (assert (= (x "a") + "a")) + (assert (= (x "a" "b" "c") + "abc")) + ; with lists + (assert (= (x ["a"]) + ["a"])) + (assert (= (x ["a"] ["b"] ["c"]) + ["a" "b" "c"])))) (defn test-shadow-subtraction []