Added type coercing to the right integer for the platform
This commit is contained in:
parent
f61d702788
commit
34275fab60
@ -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?"])
|
||||
|
@ -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")))
|
||||
|
Loading…
Reference in New Issue
Block a user