add tuple? function hy.core

`tuple?` will test if the argument is an instance of tuple.
This commit is contained in:
Tristan Cacqueray 2019-04-09 03:07:25 +00:00 committed by Kodi Arfer
parent c415c6c907
commit d793cee90a
4 changed files with 29 additions and 1 deletions

View File

@ -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
------------------------------

View File

@ -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?

View File

@ -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])

View File

@ -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]])