diff --git a/NEWS.rst b/NEWS.rst index 540b399..14842fb 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -12,6 +12,7 @@ New Features * Format strings with embedded Hy code (e.g., `f"The sum is {(+ x y)}"`) are now supported, even on Pythons earlier than 3.6. * New list? function. +* New tuple? function. Bug Fixes ------------------------------ diff --git a/docs/language/core.rst b/docs/language/core.rst index 92d41d9..7e42691 100644 --- a/docs/language/core.rst +++ b/docs/language/core.rst @@ -951,6 +951,25 @@ Returns ``True`` if *x* is a symbol. => (symbol? '[a b c]) False + +.. _tuple?-fn: + +tuple? +------ + +Usage: ``(tuple? x)`` + +Returns ``True`` if *x* is a tuple. + +.. code-block:: hy + + => (tuple? (, 42 44)) + True + + => (tuple? [42 44]) + False + + .. _zero?-fn: zero? diff --git a/hy/core/language.hy b/hy/core/language.hy index 3e1da65..93f2fa3 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -206,6 +206,9 @@ Return series of accumulated sums (or other binary function results)." (defn list? [x] (isinstance x list)) +(defn tuple? [x] + (isinstance x tuple)) + (defn symbol? [s] "Check if `s` is a symbol." (instance? HySymbol s)) @@ -461,4 +464,4 @@ Even objects with the __name__ magic will work." macroexpand-1 mangle map merge-with multicombinations name neg? none? nth numeric? odd? partition permutations pos? product range read read-str remove repeat repeatedly rest reduce second some string string? symbol? - take take-nth take-while unmangle xor tee zero? zip zip-longest]) + take take-nth take-while tuple? unmangle xor tee zero? zip zip-longest]) diff --git a/tests/native_tests/core.hy b/tests/native_tests/core.hy index 53efc3f..995ff53 100644 --- a/tests/native_tests/core.hy +++ b/tests/native_tests/core.hy @@ -272,6 +272,11 @@ result['y in globals'] = 'y' in globals()") (assert-false (list? "hello")) (assert-true (list? [1 2 3]))) +(defn test-tuple? [] + "NATIVE: testing the tuple? function" + (assert-false (tuple? [4 5])) + (assert-true (tuple? (, 4 5)))) + (defn test-gensym [] "NATIVE: testing the gensym function" (import [hy.models [HySymbol]])