Add zero? predicate to check if an object is zero

This commit is contained in:
kaizoku 2013-09-02 02:28:21 -07:00
parent e693a0267a
commit b892ec4e66
4 changed files with 40 additions and 1 deletions

View File

@ -16,3 +16,4 @@
* Guillermo Vayá <guivaya@gmail.com>
* Bob Tolbert <bob@tolbert.org>
* Ralph Möritz <ralph.moeritz@outlook.com>
* Josh McLaughlin <josh@phear.cc>

View File

@ -270,6 +270,27 @@ Return True if x is greater than zero (0).
False
.. _zero?-fn:
zero?
----
Usage: ``(zero? x)``
Return True if x is zero (0).
.. code-block:: clojure
=> (zero? 3)
False
=> (zero? -2)
False
=> (zero? 0)
True
Sequence Functions
=======================

View File

@ -154,7 +154,12 @@
(yield val)
(break)))))
(defn zero? [n]
"Return true if n is 0"
(_numeric_check n)
(= n 0))
(def *exports* ["cycle" "dec" "distinct" "drop" "even?" "filter" "inc"
"instance?" "iterable?" "iterate" "iterator?" "neg?"
"none?" "nth" "numeric?" "odd?" "pos?" "remove" "repeat"
"repeatedly" "take" "take_nth" "take_while"])
"repeatedly" "take" "take_nth" "take_while" "zero?"])

View File

@ -181,6 +181,18 @@
(try (do (neg? None) (assert False))
(catch [e [TypeError]] (assert (in "not a number" (str e))))))
(defn test-zero []
"NATIVE: testing the zero? function"
(assert-false (zero? -2))
(assert-false (zero? 1))
(assert-true (zero? 0))
(try (do (zero? "foo") (assert False))
(catch [e [TypeError]] (assert (in "not a number" (str e)))))
(try (do (zero? []) (assert False))
(catch [e [TypeError]] (assert (in "not a number" (str e)))))
(try (do (zero? None) (assert False))
(catch [e [TypeError]] (assert (in "not a number" (str e))))))
(defn test-none []
"NATIVE: testing for `is None`"
(assert-true (none? None))