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
|
||||
|
||||
|
||||
.. _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
|
||||
@ -414,6 +394,26 @@ Return True if x is a string.
|
||||
=> (string? -2)
|
||||
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
|
||||
=======================
|
||||
|
@ -23,6 +23,18 @@
|
||||
;;;; 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]
|
||||
(if (not (numeric? x))
|
||||
(raise (TypeError (.format "{0!r} is not a number" x)))))
|
||||
@ -99,10 +111,9 @@
|
||||
|
||||
(defn integer? [x]
|
||||
"Return True if x in an integer"
|
||||
(import sys)
|
||||
(if (< (get sys.version_info 0) 3)
|
||||
(isinstance x (, int long)))
|
||||
(isinstance x int))
|
||||
(-if-python2-local-
|
||||
(isinstance x (, int long))
|
||||
(isinstance x int)))
|
||||
|
||||
(defn iterable? [x]
|
||||
"Return true if x is iterable"
|
||||
@ -178,8 +189,7 @@
|
||||
|
||||
(defn string? [x]
|
||||
"Return True if x is a string"
|
||||
(import sys)
|
||||
(if (< (get sys.version_info 0) 3)
|
||||
(-if-python2-local-
|
||||
(isinstance x (, str unicode))
|
||||
(isinstance x str)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user