From 6bc9e842e17c45086f6d07d0a83c91cf326256c3 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Tue, 2 Jul 2019 12:10:01 -0400 Subject: [PATCH] Clean up whitespace --- hy/contrib/sequences.hy | 87 +++++++++++++++------------ tests/native_tests/defclass.hy | 2 +- tests/native_tests/language.hy | 18 +++--- tests/native_tests/mathematics.hy | 26 ++++---- tests/native_tests/py36_only_tests.hy | 2 +- 5 files changed, 72 insertions(+), 63 deletions(-) diff --git a/hy/contrib/sequences.hy b/hy/contrib/sequences.hy index b794b7a..01226c9 100644 --- a/hy/contrib/sequences.hy +++ b/hy/contrib/sequences.hy @@ -3,53 +3,60 @@ ;; license. See the LICENSE. (defclass Sequence [] + (defn --init-- [self func] - "initialize a new sequence with a function to compute values" - (setv (. self func) func) - (setv (. self cache) []) - (setv (. self high-water) -1)) + "initialize a new sequence with a function to compute values" + (setv (. self func) func) + (setv (. self cache) []) + (setv (. self high-water) -1)) + (defn --getitem-- [self n] - "get nth item of sequence" - (if (hasattr n "start") - (gfor x (range n.start n.stop (or n.step 1)) - (get self x)) - (do (when (neg? n) - ; Call (len) to force the whole - ; sequence to be evaluated. - (len self)) - (if (<= n (. self high-water)) - (get (. self cache) n) - (do (while (< (. self high-water) n) - (setv (. self high-water) (inc (. self high-water))) - (.append (. self cache) (.func self (. self high-water)))) - (get self n)))))) + "get nth item of sequence" + (if (hasattr n "start") + (gfor x (range n.start n.stop (or n.step 1)) + (get self x)) + (do (when (neg? n) + ; Call (len) to force the whole + ; sequence to be evaluated. + (len self)) + (if (<= n (. self high-water)) + (get (. self cache) n) + (do (while (< (. self high-water) n) + (setv (. self high-water) (inc (. self high-water))) + (.append (. self cache) (.func self (. self high-water)))) + (get self n)))))) + (defn --iter-- [self] - "create iterator for this sequence" - (setv index 0) - (try (while True - (yield (get self index)) - (setv index (inc index))) - (except [IndexError] - (return)))) + "create iterator for this sequence" + (setv index 0) + (try (while True + (yield (get self index)) + (setv index (inc index))) + (except [IndexError] + (return)))) + (defn --len-- [self] - "length of the sequence, dangerous for infinite sequences" - (setv index (. self high-water)) - (try (while True - (get self index) - (setv index (inc index))) - (except [IndexError] - (len (. self cache))))) + "length of the sequence, dangerous for infinite sequences" + (setv index (. self high-water)) + (try (while True + (get self index) + (setv index (inc index))) + (except [IndexError] + (len (. self cache))))) + (setv max-items-in-repr 10) + (defn --str-- [self] - "string representation of this sequence" - (setv items (list (take (inc self.max-items-in-repr) self))) - (.format (if (> (len items) self.max-items-in-repr) - "[{0}, ...]" - "[{0}]") - (.join ", " (map str items)))) + "string representation of this sequence" + (setv items (list (take (inc self.max-items-in-repr) self))) + (.format (if (> (len items) self.max-items-in-repr) + "[{0}, ...]" + "[{0}]") + (.join ", " (map str items)))) + (defn --repr-- [self] - "string representation of this sequence" - (.--str-- self))) + "string representation of this sequence" + (.--str-- self))) (defmacro seq [param &rest seq-code] `(Sequence (fn ~param (do ~@seq-code)))) diff --git a/tests/native_tests/defclass.hy b/tests/native_tests/defclass.hy index 8fc76bc..e27a20e 100644 --- a/tests/native_tests/defclass.hy +++ b/tests/native_tests/defclass.hy @@ -37,7 +37,7 @@ (defclass B [] (setv x 42) (setv y (fn [self value] - (+ self.x value)))) + (+ self.x value)))) (assert (= B.x 42)) (assert (= (.y (B) 5) 47)) (setv b (B)) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index d7bf1da..e251840 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -1773,20 +1773,22 @@ macros() (defn test-pep-3115 [] (defclass member-table [dict] - (defn --init-- [self] (setv self.member-names [])) + (defn --init-- [self] + (setv self.member-names [])) (defn --setitem-- [self key value] - (if (not-in key self) - (.append self.member-names key)) - (dict.--setitem-- self key value))) + (if (not-in key self) + (.append self.member-names key)) + (dict.--setitem-- self key value))) (defclass OrderedClass [type] - (setv --prepare-- (classmethod (fn [metacls name bases] (member-table)))) + (setv --prepare-- (classmethod (fn [metacls name bases] + (member-table)))) (defn --new-- [cls name bases classdict] - (setv result (type.--new-- cls name bases (dict classdict))) - (setv result.member-names classdict.member-names) - result)) + (setv result (type.--new-- cls name bases (dict classdict))) + (setv result.member-names classdict.member-names) + result)) (defclass MyClass [:metaclass OrderedClass] (defn method1 [self] (pass)) diff --git a/tests/native_tests/mathematics.hy b/tests/native_tests/mathematics.hy index 23c9045..5069644 100644 --- a/tests/native_tests/mathematics.hy +++ b/tests/native_tests/mathematics.hy @@ -160,19 +160,19 @@ (defclass HyTestMatrix [list] (defn --matmul-- [self other] - (setv n (len self) - m (len (. other [0])) - result []) - (for [i (range m)] - (setv result-row []) - (for [j (range n)] - (setv dot-product 0) - (for [k (range (len (. self [0])))] - (+= dot-product (* (. self [i] [k]) - (. other [k] [j])))) - (.append result-row dot-product)) - (.append result result-row)) - result)) + (setv n (len self) + m (len (. other [0])) + result []) + (for [i (range m)] + (setv result-row []) + (for [j (range n)] + (setv dot-product 0) + (for [k (range (len (. self [0])))] + (+= dot-product (* (. self [i] [k]) + (. other [k] [j])))) + (.append result-row dot-product)) + (.append result result-row)) + result)) (setv first-test-matrix (HyTestMatrix [[1 2 3] [4 5 6] diff --git a/tests/native_tests/py36_only_tests.hy b/tests/native_tests/py36_only_tests.hy index 7f5908a..3ba0c4f 100644 --- a/tests/native_tests/py36_only_tests.hy +++ b/tests/native_tests/py36_only_tests.hy @@ -41,7 +41,7 @@ (defn test-pep-487 [] (defclass QuestBase [] (defn --init-subclass-- [cls swallow &kwargs kwargs] - (setv cls.swallow swallow))) + (setv cls.swallow swallow))) (defclass Quest [QuestBase :swallow "african"]) (assert (= (. (Quest) swallow) "african")))