Skip to content

Instantly share code, notes, and snippets.

Created March 12, 2019 21:23
What would you like to do?
my second clojure program: a terminal-based questionnaire!
(ns questionnaire)
(def questions
{ "What's your name?" :name
"What's your favorite color?" :color
(defn bold [text] (str "\033[1m" text "\033[0m"))
(defn prompt [question] (do (print (str (bold question) " ")) (flush) (read-line)))
(defn pairs [obj] (map (fn [key] { :key key, :value (obj key)}) (keys obj)))
(defn answer
(answer questions {}))
([questions answers]
(if (not (= {} questions))
[ current (first (pairs questions))
key (current :key)
value (current :value)
remaining (dissoc questions key)
response (prompt key)
(answer remaining (assoc answers value response))
(defn main [] (answer questions))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment