Reputation: 11
In Clojure I want to create a function that would continually ask the user for an option, execute some code depending on the option, and then quit when the user’s option is “q”.
I am comfortable will all of the various Clojure forms that work with sequences, and I could certainly finagle a Java-like solution to the above, but I cannot figure out how to do this in a “clojuresque” manner.
Thanks,
Jeffrey S
Upvotes: 1
Views: 403
Reputation:
Something like this should do the job:
(defn main-loop []
(case (read-line)
"q" nil
"a" (do (println "got a command!") (recur))
"b" (do (println "got b command!") (recur))
(do (println "got invalid command!") (recur))))
Upvotes: 4