Merge pull request #1762 from TristanCacqueray/master

add `list?` function to `hy.core`
This commit is contained in:
Kodi Arfer 2019-04-08 20:25:59 -04:00 committed by GitHub
commit c6f11a737f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 4 deletions

View File

@ -91,3 +91,4 @@
* Oskar Kvist <oskar.kvist@gmail.com>
* Brandon T. Willard <brandonwillard@gmail.com>
* Andrew R. M. <nixy@nixy.moe>
* Tristan de Cacqueray <tdecacqu@redhat.com>

View File

@ -11,6 +11,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.
Bug Fixes
------------------------------

View File

@ -899,6 +899,24 @@ Returns the first logically-true value of ``(pred x)`` for any ``x`` in
True
.. _list?-fn:
list?
-----
Usage: ``(list? x)``
Returns ``True`` if *x* is a list.
.. code-block:: hy
=> (list? '(inc 41))
True
=> (list? '42)
False
.. _string?-fn:
string?

View File

@ -18,7 +18,7 @@
(setv -registry {})
(defn hy-repr-register [types f &optional placeholder]
(for [typ (if (instance? list types) types [types])]
(for [typ (if (list? types) types [types])]
(setv (get -registry typ) (, f placeholder))))
(setv -quoting False)

View File

@ -19,7 +19,7 @@
(outer (HyExpression (map inner form)))]
[(instance? HyDict form)
(HyDict (outer (HyExpression (map inner form))))]
[(instance? list form)
[(list? form)
((type form) (outer (HyExpression (map inner form))))]
[(coll? form)
(walk inner outer (list form))]

View File

@ -203,6 +203,9 @@ Return series of accumulated sums (or other binary function results)."
"Check if x is float."
(isinstance x float))
(defn list? [x]
(isinstance x list))
(defn symbol? [s]
"Check if `s` is a symbol."
(instance? HySymbol s))
@ -454,7 +457,7 @@ Even objects with the __name__ magic will work."
disassemble drop drop-last drop-while empty? eval even? every? exec first
filter flatten float? fraction gensym group-by identity inc input instance?
integer integer? integer-char? interleave interpose islice iterable?
iterate iterator? juxt keyword keyword? last macroexpand
iterate iterator? juxt keyword keyword? last list? macroexpand
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?

View File

@ -213,7 +213,7 @@ Such 'o!' params are available within `body` as the equivalent 'g!' symbol."
(defn extract-o!-sym [arg]
(cond [(and (symbol? arg) (.startswith arg "o!"))
arg]
[(and (instance? list arg) (.startswith (first arg) "o!"))
[(and (list? arg) (.startswith (first arg) "o!"))
(first arg)]))
(setv os (list (filter identity (map extract-o!-sym args)))
gs (lfor s os (HySymbol (+ "g!" (cut s 2)))))

View File

@ -267,6 +267,11 @@ result['y in globals'] = 'y' in globals()")
(assert-true (symbol? 'im-symbol))
(assert-false (symbol? (name 'im-symbol))))
(defn test-list? []
"NATIVE: testing the list? function"
(assert-false (list? "hello"))
(assert-true (list? [1 2 3])))
(defn test-gensym []
"NATIVE: testing the gensym function"
(import [hy.models [HySymbol]])