Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created July 4, 2014 15:53
Show Gist options
  • Save trikitrok/1c8bed95a3c1e0b94ba9 to your computer and use it in GitHub Desktop.
Save trikitrok/1c8bed95a3c1e0b94ba9 to your computer and use it in GitHub Desktop.
(ns robot)
(defn robot []
(atom {:name ""}))
(defn robot-name [robot]
(let
[current-name (:name @robot)
random-name
(fn []
(let
[capital-letters
(map char (range (int \A) (+ (int \Z) 1)))
num-letters
(count capital-letters)]
(apply
str
(concat
(repeatedly
2
#(nth capital-letters (rand-int num-letters)))
(repeatedly
3
#(rand-int 10))))))]
(if (empty? current-name)
(:name (swap! robot assoc :name (random-name)))
current-name)))
(defn reset-name [robot]
(swap! robot assoc :name ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment