Merge branch 'master' into pr/489
This commit is contained in:
commit
2f751df0f6
2
AUTHORS
2
AUTHORS
@ -39,3 +39,5 @@
|
|||||||
* Fatih Kadir Akın <fka@fatihak.in>
|
* Fatih Kadir Akın <fka@fatihak.in>
|
||||||
* Jack Hooper <contact.jhooper@gmail.com>
|
* Jack Hooper <contact.jhooper@gmail.com>
|
||||||
* Brian McKenna <brian@brianmckenna.org>
|
* Brian McKenna <brian@brianmckenna.org>
|
||||||
|
* Richard Parsons <richard.lee.parsons@gmail.com>
|
||||||
|
* han semaj <sangho.nah@gmail.com>
|
||||||
|
@ -31,7 +31,7 @@ Why?
|
|||||||
|
|
||||||
Well, I wrote Hy to help people realize one thing about Python:
|
Well, I wrote Hy to help people realize one thing about Python:
|
||||||
|
|
||||||
It's really goddamn awesome.
|
It's really awesome.
|
||||||
|
|
||||||
Oh, and lisps are neat.
|
Oh, and lisps are neat.
|
||||||
|
|
||||||
|
@ -762,6 +762,9 @@ of import you can use.
|
|||||||
[os.path [exists isdir isfile]]
|
[os.path [exists isdir isfile]]
|
||||||
[sys :as systest])
|
[sys :as systest])
|
||||||
|
|
||||||
|
;; Import all module functions into current namespace
|
||||||
|
(import [sys [*]])
|
||||||
|
|
||||||
|
|
||||||
kwapply
|
kwapply
|
||||||
-------
|
-------
|
||||||
|
@ -138,6 +138,32 @@ Return True if ``coll`` is empty, i.e. ``(= 0 (len coll))``.
|
|||||||
False
|
False
|
||||||
|
|
||||||
|
|
||||||
|
.. _every?-fn:
|
||||||
|
|
||||||
|
every?
|
||||||
|
------
|
||||||
|
|
||||||
|
.. versionadded:: 0.9.13
|
||||||
|
|
||||||
|
Usage: ``(every? pred coll)``
|
||||||
|
|
||||||
|
Return True if ``(pred x)`` is logical true for every ``x`` in ``coll``, otherwise False. Return True if ``coll`` is empty.
|
||||||
|
|
||||||
|
.. code-block:: clojure
|
||||||
|
|
||||||
|
=> (every? even? [2 4 6])
|
||||||
|
True
|
||||||
|
|
||||||
|
=> (every? even? [1 3 5])
|
||||||
|
False
|
||||||
|
|
||||||
|
=> (every? even? [2 4 5])
|
||||||
|
False
|
||||||
|
|
||||||
|
=> (every? even? [])
|
||||||
|
True
|
||||||
|
|
||||||
|
|
||||||
.. _float?-fn:
|
.. _float?-fn:
|
||||||
|
|
||||||
float?
|
float?
|
||||||
@ -570,6 +596,32 @@ Return the second member of ``coll``. Equivalent to
|
|||||||
1
|
1
|
||||||
|
|
||||||
|
|
||||||
|
.. _some-fn:
|
||||||
|
|
||||||
|
some
|
||||||
|
----
|
||||||
|
|
||||||
|
.. versionadded:: 0.9.13
|
||||||
|
|
||||||
|
Usage: ``(some pred coll)``
|
||||||
|
|
||||||
|
Return True if ``(pred x)`` is logical true for any ``x`` in ``coll``, otherwise False. Return False if ``coll`` is empty.
|
||||||
|
|
||||||
|
.. code-block:: clojure
|
||||||
|
|
||||||
|
=> (some even? [2 4 6])
|
||||||
|
True
|
||||||
|
|
||||||
|
=> (some even? [1 3 5])
|
||||||
|
False
|
||||||
|
|
||||||
|
=> (some even? [1 3 6])
|
||||||
|
True
|
||||||
|
|
||||||
|
=> (some even? [])
|
||||||
|
False
|
||||||
|
|
||||||
|
|
||||||
.. _string?-fn:
|
.. _string?-fn:
|
||||||
|
|
||||||
string?
|
string?
|
||||||
|
@ -75,12 +75,12 @@
|
|||||||
(defn distinct [coll]
|
(defn distinct [coll]
|
||||||
"Return a generator from the original collection with duplicates
|
"Return a generator from the original collection with duplicates
|
||||||
removed"
|
removed"
|
||||||
(let [[seen []] [citer (iter coll)]]
|
(let [[seen (set)] [citer (iter coll)]]
|
||||||
(for* [val citer]
|
(for* [val citer]
|
||||||
(if (not_in val seen)
|
(if (not_in val seen)
|
||||||
(do
|
(do
|
||||||
(yield val)
|
(yield val)
|
||||||
(.append seen val))))))
|
(.add seen val))))))
|
||||||
|
|
||||||
(defn drop [count coll]
|
(defn drop [count coll]
|
||||||
"Drop `count` elements from `coll` and yield back the rest"
|
"Drop `count` elements from `coll` and yield back the rest"
|
||||||
@ -108,6 +108,10 @@
|
|||||||
(_numeric-check n)
|
(_numeric-check n)
|
||||||
(= (% n 2) 0))
|
(= (% n 2) 0))
|
||||||
|
|
||||||
|
(defn every? [pred coll]
|
||||||
|
"Return true if (pred x) is logical true for every x in coll, else false"
|
||||||
|
(all (map pred coll)))
|
||||||
|
|
||||||
(defn fake-source-positions [tree]
|
(defn fake-source-positions [tree]
|
||||||
"Fake the source positions for a given tree"
|
"Fake the source positions for a given tree"
|
||||||
(if (and (iterable? tree) (not (string? tree)))
|
(if (and (iterable? tree) (not (string? tree)))
|
||||||
@ -294,6 +298,10 @@
|
|||||||
"Return second item from `coll`"
|
"Return second item from `coll`"
|
||||||
(get coll 1))
|
(get coll 1))
|
||||||
|
|
||||||
|
(defn some [pred coll]
|
||||||
|
"Return true if (pred x) is logical true for any x in coll, else false"
|
||||||
|
(any (map pred coll)))
|
||||||
|
|
||||||
(defn string [x]
|
(defn string [x]
|
||||||
"Cast x as current string implementation"
|
"Cast x as current string implementation"
|
||||||
(if-python2
|
(if-python2
|
||||||
@ -338,9 +346,9 @@
|
|||||||
(= n 0))
|
(= n 0))
|
||||||
|
|
||||||
(def *exports* '[calling-module-name coll? cons cons? cycle dec distinct
|
(def *exports* '[calling-module-name coll? cons cons? cycle dec distinct
|
||||||
disassemble drop drop-while empty? even? first filter
|
disassemble drop drop-while empty? even? every? first filter
|
||||||
flatten float? gensym identity inc instance? integer
|
flatten float? gensym identity inc instance? integer
|
||||||
integer? integer-char? iterable? iterate iterator?
|
integer? integer-char? iterable? iterate iterator?
|
||||||
list* macroexpand macroexpand-1 neg? nil? none? nth
|
list* macroexpand macroexpand-1 neg? nil? none? nth
|
||||||
numeric? odd? pos? remove repeat repeatedly rest second
|
numeric? odd? pos? remove repeat repeatedly rest second
|
||||||
string string? take take-nth take-while zero?])
|
some string string? take take-nth take-while zero?])
|
||||||
|
@ -123,6 +123,13 @@
|
|||||||
(try (even? None)
|
(try (even? None)
|
||||||
(catch [e [TypeError]] (assert (in "not a number" (str e))))))
|
(catch [e [TypeError]] (assert (in "not a number" (str e))))))
|
||||||
|
|
||||||
|
(defn test-every? []
|
||||||
|
"NATIVE: testing the every? function"
|
||||||
|
(assert-true (every? even? [2 4 6]))
|
||||||
|
(assert-false (every? even? [1 3 5]))
|
||||||
|
(assert-false (every? even? [2 4 5]))
|
||||||
|
(assert-true (every? even? [])))
|
||||||
|
|
||||||
(defn test-filter []
|
(defn test-filter []
|
||||||
"NATIVE: testing the filter function"
|
"NATIVE: testing the filter function"
|
||||||
(setv res (list (filter pos? [ 1 2 3 -4 5])))
|
(setv res (list (filter pos? [ 1 2 3 -4 5])))
|
||||||
@ -399,6 +406,13 @@
|
|||||||
(assert-equal 2 (second [1 2]))
|
(assert-equal 2 (second [1 2]))
|
||||||
(assert-equal 3 (second [2 3 4])))
|
(assert-equal 3 (second [2 3 4])))
|
||||||
|
|
||||||
|
(defn test-some []
|
||||||
|
"NATIVE: testing the some function"
|
||||||
|
(assert-true (some even? [2 4 6]))
|
||||||
|
(assert-false (some even? [1 3 5]))
|
||||||
|
(assert-true (some even? [1 3 6]))
|
||||||
|
(assert-false (some even? [])))
|
||||||
|
|
||||||
(defn test-string? []
|
(defn test-string? []
|
||||||
"NATIVE: testing string?"
|
"NATIVE: testing string?"
|
||||||
(assert-true (string? "foo"))
|
(assert-true (string? "foo"))
|
||||||
@ -456,4 +470,3 @@
|
|||||||
(assert-equal res [None None])
|
(assert-equal res [None None])
|
||||||
(setv res (list (take-while (fn [x] (not (none? x))) [1 2 3 4 None 5 6 None 7])))
|
(setv res (list (take-while (fn [x] (not (none? x))) [1 2 3 4 None 5 6 None 7])))
|
||||||
(assert-equal res [1 2 3 4]))
|
(assert-equal res [1 2 3 4]))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user