diff --git a/docs/language/core.rst b/docs/language/core.rst index d0118b1..8a34549 100644 --- a/docs/language/core.rst +++ b/docs/language/core.rst @@ -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 ======================= diff --git a/hy/core/language.hy b/hy/core/language.hy index 66bde39..610078f 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -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)))