diff --git a/hy/core/language.hy b/hy/core/language.hy index a96b25d..ff98a11 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -23,6 +23,8 @@ ;;;; to make functional programming slightly easier. ;;;; +(import [hy._compat [long-type]]) ; long for python2, int for python3 + (defn _numeric-check [x] (if (not (numeric? x)) (raise (TypeError (.format "{0!r} is not a number" x))))) @@ -97,11 +99,13 @@ (defn instance? [klass x] (isinstance x klass)) +(defn integer [x] + "Return Hy kind of integer" + (long-type x)) + (defn integer? [x] "Return True if x in an integer" - (if-python2 - (isinstance x (, int long)) - (isinstance x int))) + (isinstance x (, int long-type))) (defn iterable? [x] "Return true if x is iterable" @@ -213,8 +217,7 @@ (= n 0)) (def *exports* ["cycle" "dec" "distinct" "drop" "drop_while" "empty?" - "even?" "filter" "float?" "inc" - "instance?" "integer?" "iterable?" "iterate" "iterator?" "neg?" - "none?" "nth" "numeric?" "odd?" "pos?" "remove" "repeat" - "repeatedly" "second" "string?" "take" "take_nth" "take_while" - "zero?"]) + "even?" "filter" "float?" "inc" "instance?" "integer" "integer?" + "iterable?" "iterate" "iterator?" "neg?" "none?" "nth" + "numeric?" "odd?" "pos?" "remove" "repeat" "repeatedly" "second" + "string?" "take" "take_nth" "take_while" "zero?"]) diff --git a/tests/native_tests/core.hy b/tests/native_tests/core.hy index e9d73c7..2f6b717 100644 --- a/tests/native_tests/core.hy +++ b/tests/native_tests/core.hy @@ -171,6 +171,8 @@ (assert-true (integer? 0)) (assert-true (integer? 3)) (assert-true (integer? -3)) + (assert-true (integer? (integer "-3"))) + (assert-true (integer? (integer 3))) (assert-false (integer? 4.2)) (assert-false (integer? None)) (assert-false (integer? "foo")))