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>
|
||||
* Jack Hooper <contact.jhooper@gmail.com>
|
||||
* 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:
|
||||
|
||||
It's really goddamn awesome.
|
||||
It's really awesome.
|
||||
|
||||
Oh, and lisps are neat.
|
||||
|
||||
|
@ -762,6 +762,9 @@ of import you can use.
|
||||
[os.path [exists isdir isfile]]
|
||||
[sys :as systest])
|
||||
|
||||
;; Import all module functions into current namespace
|
||||
(import [sys [*]])
|
||||
|
||||
|
||||
kwapply
|
||||
-------
|
||||
|
@ -138,6 +138,32 @@ Return True if ``coll`` is empty, i.e. ``(= 0 (len coll))``.
|
||||
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?
|
||||
@ -570,6 +596,32 @@ Return the second member of ``coll``. Equivalent to
|
||||
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?
|
||||
|
@ -75,12 +75,12 @@
|
||||
(defn distinct [coll]
|
||||
"Return a generator from the original collection with duplicates
|
||||
removed"
|
||||
(let [[seen []] [citer (iter coll)]]
|
||||
(let [[seen (set)] [citer (iter coll)]]
|
||||
(for* [val citer]
|
||||
(if (not_in val seen)
|
||||
(do
|
||||
(yield val)
|
||||
(.append seen val))))))
|
||||
(.add seen val))))))
|
||||
|
||||
(defn drop [count coll]
|
||||
"Drop `count` elements from `coll` and yield back the rest"
|
||||
@ -108,6 +108,10 @@
|
||||
(_numeric-check n)
|
||||
(= (% 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]
|
||||
"Fake the source positions for a given tree"
|
||||
(if (and (iterable? tree) (not (string? tree)))
|
||||
@ -294,6 +298,10 @@
|
||||
"Return second item from `coll`"
|
||||
(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]
|
||||
"Cast x as current string implementation"
|
||||
(if-python2
|
||||
@ -338,9 +346,9 @@
|
||||
(= n 0))
|
||||
|
||||
(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
|
||||
integer? integer-char? iterable? iterate iterator?
|
||||
list* macroexpand macroexpand-1 neg? nil? none? nth
|
||||
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)
|
||||
(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 []
|
||||
"NATIVE: testing the filter function"
|
||||
(setv res (list (filter pos? [ 1 2 3 -4 5])))
|
||||
@ -399,6 +406,13 @@
|
||||
(assert-equal 2 (second [1 2]))
|
||||
(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? []
|
||||
"NATIVE: testing string?"
|
||||
(assert-true (string? "foo"))
|
||||
@ -456,4 +470,3 @@
|
||||
(assert-equal res [None None])
|
||||
(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]))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user