One more commit to change the test for Python 2/3 to a macro
Note that this can't use the macro in hy.core.macros so there is a local copy in language.hy
This commit is contained in:
parent
9d2ad4b4ff
commit
d9dee8ec67
@ -361,26 +361,6 @@ Raises ``TypeError`` if ``(not (numeric? x))``.
|
|||||||
False
|
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
|
|
||||||
|
|
||||||
.. _second-fn:
|
.. _second-fn:
|
||||||
|
|
||||||
second
|
second
|
||||||
@ -414,6 +394,26 @@ Return True if x is a string.
|
|||||||
=> (string? -2)
|
=> (string? -2)
|
||||||
False
|
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
|
Sequence Functions
|
||||||
=======================
|
=======================
|
||||||
|
@ -23,6 +23,18 @@
|
|||||||
;;;; to make functional programming slightly easier.
|
;;;; to make functional programming slightly easier.
|
||||||
;;;;
|
;;;;
|
||||||
|
|
||||||
|
;;;; These are local-only macros that are copied from hy.core.macros since
|
||||||
|
;;;; those are invisible here.
|
||||||
|
(defmacro -if-python2-local- [python2-form python3-form]
|
||||||
|
(import sys)
|
||||||
|
(if (< (get sys.version_info 0) 3)
|
||||||
|
python2-form
|
||||||
|
python3-form))
|
||||||
|
|
||||||
|
;;;;
|
||||||
|
;;;;
|
||||||
|
|
||||||
|
|
||||||
(defn _numeric-check [x]
|
(defn _numeric-check [x]
|
||||||
(if (not (numeric? x))
|
(if (not (numeric? x))
|
||||||
(raise (TypeError (.format "{0!r} is not a number" x)))))
|
(raise (TypeError (.format "{0!r} is not a number" x)))))
|
||||||
@ -99,10 +111,9 @@
|
|||||||
|
|
||||||
(defn integer? [x]
|
(defn integer? [x]
|
||||||
"Return True if x in an integer"
|
"Return True if x in an integer"
|
||||||
(import sys)
|
(-if-python2-local-
|
||||||
(if (< (get sys.version_info 0) 3)
|
(isinstance x (, int long))
|
||||||
(isinstance x (, int long)))
|
(isinstance x int)))
|
||||||
(isinstance x int))
|
|
||||||
|
|
||||||
(defn iterable? [x]
|
(defn iterable? [x]
|
||||||
"Return true if x is iterable"
|
"Return true if x is iterable"
|
||||||
@ -178,8 +189,7 @@
|
|||||||
|
|
||||||
(defn string? [x]
|
(defn string? [x]
|
||||||
"Return True if x is a string"
|
"Return True if x is a string"
|
||||||
(import sys)
|
(-if-python2-local-
|
||||||
(if (< (get sys.version_info 0) 3)
|
|
||||||
(isinstance x (, str unicode))
|
(isinstance x (, str unicode))
|
||||||
(isinstance x str)))
|
(isinstance x str)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user