Add zero? predicate to check if an object is zero
This commit is contained in:
parent
e693a0267a
commit
b892ec4e66
1
AUTHORS
1
AUTHORS
@ -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>
|
||||
|
@ -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
|
||||
=======================
|
||||
|
||||
|
@ -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?"])
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user