Shadow '+' to handle string/list concatenation
This commit is contained in:
parent
7e5befa615
commit
c8985a898b
@ -26,9 +26,12 @@
|
|||||||
|
|
||||||
(defn + [&rest args]
|
(defn + [&rest args]
|
||||||
"Shadow + operator for when we need to import / map it against something"
|
"Shadow + operator for when we need to import / map it against something"
|
||||||
(if (= (len args) 0)
|
(let [[count (len args)]]
|
||||||
0
|
(if (zero? count)
|
||||||
(sum args))) ; shortcut here.
|
(raise (TypeError "Need at least 1 argument to add/concatenate"))
|
||||||
|
(if (= count 1)
|
||||||
|
(get args 0)
|
||||||
|
(reduce operator.add args)))))
|
||||||
|
|
||||||
|
|
||||||
(defn - [&rest args]
|
(defn - [&rest args]
|
||||||
|
@ -12,6 +12,7 @@ from .native_tests.when import * # noqa
|
|||||||
from .native_tests.with_decorator import * # noqa
|
from .native_tests.with_decorator import * # noqa
|
||||||
from .native_tests.core import * # noqa
|
from .native_tests.core import * # noqa
|
||||||
from .native_tests.reader_macros 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.with_test import * # noqa
|
||||||
from .native_tests.contrib.anaphoric import * # noqa
|
from .native_tests.contrib.anaphoric import * # noqa
|
||||||
from .native_tests.contrib.loop import * # noqa
|
from .native_tests.contrib.loop import * # noqa
|
||||||
|
@ -1,11 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn test-shadow-addition []
|
(defn test-shadow-addition []
|
||||||
"NATIVE: test shadow addition"
|
"NATIVE: test shadow addition"
|
||||||
(let [[x +]]
|
(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) 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 []
|
(defn test-shadow-subtraction []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user