Merge pull request #1762 from TristanCacqueray/master
add `list?` function to `hy.core`
This commit is contained in:
commit
c6f11a737f
1
AUTHORS
1
AUTHORS
@ -91,3 +91,4 @@
|
|||||||
* Oskar Kvist <oskar.kvist@gmail.com>
|
* Oskar Kvist <oskar.kvist@gmail.com>
|
||||||
* Brandon T. Willard <brandonwillard@gmail.com>
|
* Brandon T. Willard <brandonwillard@gmail.com>
|
||||||
* Andrew R. M. <nixy@nixy.moe>
|
* Andrew R. M. <nixy@nixy.moe>
|
||||||
|
* Tristan de Cacqueray <tdecacqu@redhat.com>
|
||||||
|
1
NEWS.rst
1
NEWS.rst
@ -11,6 +11,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.
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
------------------------------
|
------------------------------
|
||||||
|
@ -899,6 +899,24 @@ Returns the first logically-true value of ``(pred x)`` for any ``x`` in
|
|||||||
True
|
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?-fn:
|
||||||
|
|
||||||
string?
|
string?
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
(setv -registry {})
|
(setv -registry {})
|
||||||
(defn hy-repr-register [types f &optional placeholder]
|
(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 (get -registry typ) (, f placeholder))))
|
||||||
|
|
||||||
(setv -quoting False)
|
(setv -quoting False)
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
(outer (HyExpression (map inner form)))]
|
(outer (HyExpression (map inner form)))]
|
||||||
[(instance? HyDict form)
|
[(instance? HyDict form)
|
||||||
(HyDict (outer (HyExpression (map inner form))))]
|
(HyDict (outer (HyExpression (map inner form))))]
|
||||||
[(instance? list form)
|
[(list? form)
|
||||||
((type form) (outer (HyExpression (map inner form))))]
|
((type form) (outer (HyExpression (map inner form))))]
|
||||||
[(coll? form)
|
[(coll? form)
|
||||||
(walk inner outer (list form))]
|
(walk inner outer (list form))]
|
||||||
|
@ -203,6 +203,9 @@ Return series of accumulated sums (or other binary function results)."
|
|||||||
"Check if x is float."
|
"Check if x is float."
|
||||||
(isinstance x float))
|
(isinstance x float))
|
||||||
|
|
||||||
|
(defn list? [x]
|
||||||
|
(isinstance x list))
|
||||||
|
|
||||||
(defn symbol? [s]
|
(defn symbol? [s]
|
||||||
"Check if `s` is a symbol."
|
"Check if `s` is a symbol."
|
||||||
(instance? HySymbol s))
|
(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
|
disassemble drop drop-last drop-while empty? eval even? every? exec first
|
||||||
filter flatten float? fraction gensym group-by identity inc input instance?
|
filter flatten float? fraction gensym group-by identity inc input instance?
|
||||||
integer integer? integer-char? interleave interpose islice iterable?
|
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
|
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?
|
||||||
|
@ -213,7 +213,7 @@ Such 'o!' params are available within `body` as the equivalent 'g!' symbol."
|
|||||||
(defn extract-o!-sym [arg]
|
(defn extract-o!-sym [arg]
|
||||||
(cond [(and (symbol? arg) (.startswith arg "o!"))
|
(cond [(and (symbol? arg) (.startswith arg "o!"))
|
||||||
arg]
|
arg]
|
||||||
[(and (instance? list arg) (.startswith (first arg) "o!"))
|
[(and (list? arg) (.startswith (first arg) "o!"))
|
||||||
(first arg)]))
|
(first arg)]))
|
||||||
(setv os (list (filter identity (map extract-o!-sym args)))
|
(setv os (list (filter identity (map extract-o!-sym args)))
|
||||||
gs (lfor s os (HySymbol (+ "g!" (cut s 2)))))
|
gs (lfor s os (HySymbol (+ "g!" (cut s 2)))))
|
||||||
|
@ -267,6 +267,11 @@ result['y in globals'] = 'y' in globals()")
|
|||||||
(assert-true (symbol? 'im-symbol))
|
(assert-true (symbol? 'im-symbol))
|
||||||
(assert-false (symbol? (name '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 []
|
(defn test-gensym []
|
||||||
"NATIVE: testing the gensym function"
|
"NATIVE: testing the gensym function"
|
||||||
(import [hy.models [HySymbol]])
|
(import [hy.models [HySymbol]])
|
||||||
|
Loading…
Reference in New Issue
Block a user