tracks/clojure/exercises/robot-name/src/example.clj in trackler-2.0.0.8 vs tracks/clojure/exercises/robot-name/src/example.clj in trackler-2.0.0.9
- old
+ new
@@ -1,19 +1,16 @@
(ns robot-name)
-(defn robot []
- {:name (atom "")})
-
-(def random (java.util.Random.))
-(def letters (map char (range 65 91)))
-(defn generate-name []
+(def ^:private random (java.util.Random.))
+(def ^:private letters (map char (range 65 91)))
+(defn- generate-name []
(str (apply str (take 2 (shuffle letters)))
(+ 100 (.nextInt random 899))))
+(defn robot []
+ (atom {:name (generate-name)}))
+
(defn robot-name [robot]
- (let [n @(:name robot)]
- (if (= "" n)
- (swap! (:name robot) #(str %1 (generate-name)))
- n)))
+ (:name @robot))
(defn reset-name [robot]
- (swap! (:name robot) (fn [_] "")))
+ (swap! robot assoc :name (generate-name)))