Merge pull request #1770 from TristanCacqueray/add-tuple

add `tuple?` function `hy.core`
This commit is contained in:
Kodi Arfer 2019-04-23 15:33:02 -04:00 committed by GitHub
commit 10e5c9fdaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)}"`) * Format strings with embedded Hy code (e.g., `f"The sum is {(+ x y)}"`)
are now supported, even on Pythons earlier than 3.6. are now supported, even on Pythons earlier than 3.6.
* New list? function. * New list? function.
* New tuple? function.
Bug Fixes Bug Fixes
------------------------------ ------------------------------

View File

@ -951,6 +951,25 @@ Returns ``True`` if *x* is a symbol.
=> (symbol? '[a b c]) => (symbol? '[a b c])
False 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?-fn:
zero? zero?

View File

@ -206,6 +206,9 @@ Return series of accumulated sums (or other binary function results)."
(defn list? [x] (defn list? [x]
(isinstance x list)) (isinstance x list))
(defn tuple? [x]
(isinstance x tuple))
(defn symbol? [s] (defn symbol? [s]
"Check if `s` is a symbol." "Check if `s` is a symbol."
(instance? HySymbol s)) (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 macroexpand-1 mangle map merge-with multicombinations name neg? none? nth
numeric? odd? partition permutations pos? product range read read-str numeric? odd? partition permutations pos? product range read read-str
remove repeat repeatedly rest reduce second some string string? symbol? 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-false (list? "hello"))
(assert-true (list? [1 2 3]))) (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 [] (defn test-gensym []
"NATIVE: testing the gensym function" "NATIVE: testing the gensym function"
(import [hy.models [HySymbol]]) (import [hy.models [HySymbol]])