From 39fe42f23452ed58ba9644fe6351027b25c1ef69 Mon Sep 17 00:00:00 2001 From: Spenser Truex Date: Tue, 3 Sep 2019 21:30:51 -0700 Subject: [PATCH] Remove trailing whitespace which is in almost every file. --- src/examples/atom_snake.clj | 60 +++++++++---------- src/examples/chat.clj | 4 +- src/examples/concurrency.clj | 8 +-- src/examples/error_kit.clj | 19 ++---- src/examples/exploring.clj | 12 ++-- src/examples/functional.clj | 17 +++--- src/examples/import_static.clj | 2 +- src/examples/interop.clj | 18 +++--- src/examples/introduction.clj | 8 +-- src/examples/io.clj | 4 +- src/examples/lazy_index_of_any.clj | 1 - src/examples/life_without_multi.clj | 2 +- src/examples/macros.clj | 9 +-- src/examples/macros/bench_1.clj | 4 +- src/examples/macros/chain_2.clj | 2 +- src/examples/male_female.clj | 3 +- src/examples/male_female_seq.clj | 3 +- src/examples/memoized_male_female.clj | 5 +- src/examples/multimethods.clj | 5 +- src/examples/multimethods/account.clj | 3 +- .../multimethods/service_charge_1.clj | 1 - .../multimethods/service_charge_3.clj | 3 - src/examples/pi.clj | 10 ++-- src/examples/preface.clj | 2 +- src/examples/protocols.clj | 6 +- src/examples/replace_symbol.clj | 6 +- src/examples/sequences.clj | 19 +++--- src/examples/server/step_1.clj | 2 - src/examples/server/step_2.clj | 4 +- src/examples/snake.clj | 37 ++++++------ src/examples/tasklist.clj | 2 +- src/examples/test.clj | 6 +- src/examples/trampoline.clj | 4 +- src/examples/utils.clj | 18 +++--- src/examples/wallingford.clj | 6 +- 35 files changed, 137 insertions(+), 178 deletions(-) diff --git a/src/examples/atom_snake.clj b/src/examples/atom_snake.clj index 0de8d24..b2661ac 100644 --- a/src/examples/atom_snake.clj +++ b/src/examples/atom_snake.clj @@ -1,12 +1,13 @@ ; Inspired by the snakes the have gone before: ; Abhishek Reddy's snake: http://www.plt1.com/1070/even-smaller-snake/ -; Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html +; Mark Volkmann's snake: http://www.ociweb.com/mark/programming/ClojureSnake.html (ns examples.atom-snake - (:import (java.awt Color Dimension) - (javax.swing JPanel JFrame Timer JOptionPane) - (java.awt.event ActionListener KeyListener)) - (:use examples.import-static)) + (:require [examples.import-static :refer :all]) + (:import [java.awt Color Dimension] + [java.awt.event ActionListener KeyListener] + [javax.swing JFrame JOptionPane JPanel Timer])) + (import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN) ; ---------------------------------------------------------- @@ -17,34 +18,34 @@ (def point-size 10) (def turn-millis 75) (def win-length 5) -(def dirs { VK_LEFT [-1 0] +(def dirs { VK_LEFT [-1 0] VK_RIGHT [ 1 0] - VK_UP [ 0 -1] + VK_UP [ 0 -1] VK_DOWN [ 0 1]}) -(defn add-points [& pts] +(defn add-points [& pts] (vec (apply map + pts))) -(defn point-to-screen-rect [pt] - (map #(* point-size %) +(defn point-to-screen-rect [pt] + (map #(* point-size %) [(pt 0) (pt 1) 1 1])) -(defn create-apple [] +(defn create-apple [] {:location [(rand-int width) (rand-int height)] :color (Color. 210 50 90) - :type :apple}) + :type :apple}) (defn create-snake [] - {:body (list [1 1]) + {:body (list [1 1]) :dir [1 0] :type :snake :color (Color. 15 160 70)}) (defn move [{:keys [body dir] :as snake} & grow] - (assoc snake :body (cons (add-points (first body) dir) + (assoc snake :body (cons (add-points (first body) dir) (if grow body (butlast body))))) -(defn turn [snake newdir] +(defn turn [snake newdir] (if newdir (assoc snake :dir newdir) snake)) (defn win? [{body :body}] @@ -74,28 +75,28 @@ ; ---------------------------------------------------------- ; gui ; ---------------------------------------------------------- -(defn fill-point [g pt color] +(defn fill-point [g pt color] (let [[x y width height] (point-to-screen-rect pt)] - (.setColor g color) + (.setColor g color) (.fillRect g x y width height))) (defmulti paint (fn [g object & _] (:type object))) -(defmethod paint :apple [g {:keys [location color]}] +(defmethod paint :apple [g {:keys [location color]}] (fill-point g location color)) -(defmethod paint :snake [g {:keys [body color]}] +(defmethod paint :snake [g {:keys [body color]}] (doseq [point body] (fill-point g point color))) (defn game-panel [frame game] (proxy [JPanel ActionListener KeyListener] [] - (paintComponent [g] + (paintComponent [g] (proxy-super paintComponent g) (paint g (@game :snake)) (paint g (@game :apple))) ; START: swap! - (actionPerformed [e] + (actionPerformed [e] (swap! game update-positions) (when (lose? (@game :snake)) (swap! game reset-game) @@ -105,26 +106,25 @@ (swap! game reset-game) (JOptionPane/showMessageDialog frame "You win!")) (.repaint this)) - (keyPressed [e] + (keyPressed [e] (swap! game update-direction (dirs (.getKeyCode e)))) - (getPreferredSize [] - (Dimension. (* (inc width) point-size) + (getPreferredSize [] + (Dimension. (* (inc width) point-size) (* (inc height) point-size))) (keyReleased [e]) (keyTyped [e]))) -(defn game [] +(defn game [] (let [game (atom (reset-game {})) frame (JFrame. "Snake") panel (game-panel frame game) timer (Timer. turn-millis panel)] - (doto panel + (doto panel (.setFocusable true) (.addKeyListener panel)) - (doto frame + (doto frame (.add panel) (.pack) (.setVisible true)) - (.start timer) - [game, timer])) - + (.start timer) + [game, timer])) diff --git a/src/examples/chat.clj b/src/examples/chat.clj index 065c61f..4d2513e 100644 --- a/src/examples/chat.clj +++ b/src/examples/chat.clj @@ -6,7 +6,7 @@ ; START: messages (def messages (ref ())) -; END: messages +; END: messages ; START: validate-message-list (def validate-message-list @@ -20,7 +20,7 @@ (defn naive-add-message [msg] (dosync (ref-set messages (cons msg @messages)))) ; END: naive-add-message - + ; START: add-message (defn add-message [msg] (dosync (alter messages conj msg))) diff --git a/src/examples/concurrency.clj b/src/examples/concurrency.clj index 6e56c89..d9187b6 100644 --- a/src/examples/concurrency.clj +++ b/src/examples/concurrency.clj @@ -22,11 +22,11 @@ ; START: demo-memoize (defn demo-memoize [] - (time + (time (dorun (binding [slow-double (memoize slow-double)] (calls-slow-double))))) -; END: demo-memoize +; END: demo-memoize ; START: backup-agent (def backup-agent (agent "output/messages-backup.clj")) @@ -34,12 +34,10 @@ ; START: add-message-with-backup (defn add-message-with-backup [msg] - (dosync + (dosync (let [snapshot (commute messages conj msg)] (send-off backup-agent (fn [filename] (spit filename snapshot) filename)) snapshot))) ; END: add-message-with-backup - - diff --git a/src/examples/error_kit.clj b/src/examples/error_kit.clj index ff0980f..b44f50c 100644 --- a/src/examples/error_kit.clj +++ b/src/examples/error_kit.clj @@ -13,41 +13,34 @@ (next (re-matches #"(\d+-\d+-\d+) (\d+:\d+:\d+) (\w+) (.*)" entry)) (raise malformed-log-entry entry))) -(def bad-log +(def bad-log ["2008-10-05 12:14:00 WARN Some warning message here..." "<>" "2008-10-05 12:14:00 INFO End of the current log..."]) -(def good-log +(def good-log ["2008-10-05 12:14:00 WARN Some warning message here..." "2008-10-05 12:14:00 INFO End of the current log..."]) ; Example 1. Continue calculation with replacement value (defn parse-or-nil [logseq] - (with-handler + (with-handler (vec (map parse-log-entry logseq)) (handle malformed-log-entry [msg] (continue-with nil)))) - + ; Example 2. Continue calculation with logging & replacement value (defn parse-or-warn [logseq] - (with-handler + (with-handler (vec (map parse-log-entry logseq)) (handle malformed-log-entry [msg] (continue-with (println "****warning****: invalid log: " msg))))) ; Example 3. Caller can choose from a fixed set of contiue strategies. (defn parse-or-continue [logseq] - (let [parse-log-entry + (let [parse-log-entry (fn [entry] (with-handler (parse-log-entry entry) (bind-continue skip [msg] nil) (bind-continue log [msg] (println "****warning****: invalid log: " msg))))] (vec (map parse-log-entry logseq)))) - - - - - - - \ No newline at end of file diff --git a/src/examples/exploring.clj b/src/examples/exploring.clj index 892404c..a7d14f0 100644 --- a/src/examples/exploring.clj +++ b/src/examples/exploring.clj @@ -6,7 +6,7 @@ ; START:date (defn date [person-1 person-2 & chaperones] - (println person-1 "and" person-2 + (println person-1 "and" person-2 "went out with" (count chaperones) "chaperones.")) ; END:date @@ -26,7 +26,7 @@ (defn is-small? [number] (if (< number 100) "yes" - (do + (do (println "Saw a big number" number) "no"))) ; END:do @@ -54,7 +54,7 @@ ; START: index-filter (defn index-filter [pred coll] - (when pred + (when pred (for [[idx elt] (indexed coll) :when (pred elt)] idx))) ; END: index-filter ; START:index-of-any @@ -63,7 +63,7 @@ ; END: index-of-any ; START:greeting -(defn greeting +(defn greeting "Returns a greeting of the form 'Hello, username.'" [username] (str "Hello, " username)) @@ -71,7 +71,7 @@ (def simple-greeting greeting) ; START:greeting-with-default -(defn greeting +(defn greeting "Returns a greeting of the form 'Hello, username.' Default username is 'world'." ([] (greeting "world")) @@ -84,7 +84,7 @@ (> (count word) 2)) ; END:indexable-word -; START:indexable-words +; START:indexable-words (defn indexable-words [text] (let [indexable-word? (fn [w] (> (count w) 2))] (filter indexable-word? (str/split text #"\W+")))) diff --git a/src/examples/functional.clj b/src/examples/functional.clj index f4ec817..4312924 100644 --- a/src/examples/functional.clj +++ b/src/examples/functional.clj @@ -20,10 +20,10 @@ (fib 0N 1N n))) ;