Merge pull request #480 from agentultra/digit-char

Add integer-char? to core
This commit is contained in:
J Kenneth King 2014-01-28 15:15:22 -08:00
commit 20d27b23e9
2 changed files with 23 additions and 6 deletions

View File

@ -177,6 +177,13 @@
"Return True if x in an integer"
(isinstance x (, int long-type)))
(defn integer-char? [x]
"Return True if char `x` parses as an integer"
(try
(integer? (int x))
(catch [e ValueError] False)
(catch [e TypeError] False)))
(defn iterable? [x]
"Return true if x is iterable"
(try (do (iter x) true)
@ -314,9 +321,11 @@
(_numeric_check n)
(= n 0))
(def *exports* '[calling-module-name coll? cycle dec distinct disassemble
drop drop-while empty? even? first filter flatten float?
gensym identity inc instance? integer integer? iterable?
iterate iterator? macroexpand macroexpand-1 neg? nil?
none? nth numeric? odd? pos? remove repeat repeatedly
rest second string string? take take-nth take-while zero?])
(def *exports* '[calling-module-name coll? cycle dec distinct
disassemble drop drop-while empty? even? first filter
flatten float? gensym identity inc instance? integer
integer? integer-char? iterable? iterate iterator?
macroexpand macroexpand-1 neg? nil? none? nth
numeric? odd? pos? remove repeat repeatedly rest
second string string? take take-nth take-while
zero?])

View File

@ -223,6 +223,14 @@
(assert-false (integer? None))
(assert-false (integer? "foo")))
(defn test-integer-char? []
"NATIVE: testing the integer-char? function"
(assert-true (integer-char? "1"))
(assert-true (integer-char? "-1"))
(assert-true (integer-char? (str (integer 300))))
(assert-false (integer-char? "foo"))
(assert-false (integer-char? None)))
(defn test-iterable []
"NATIVE: testing iterable? function"
;; should work for a string