Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Menu/Clojure/menu.clj
Normal file
22
Task/Menu/Clojure/menu.clj
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(defn menu [prompt choices]
|
||||
(if (empty? choices)
|
||||
""
|
||||
(let [menutxt (apply str (interleave
|
||||
(iterate inc 1)
|
||||
(map #(str \space % \newline) choices)))]
|
||||
(println menutxt)
|
||||
(print prompt)
|
||||
(flush)
|
||||
(let [index (read-string (read-line))]
|
||||
; verify
|
||||
(if (or (not (integer? index))
|
||||
(> index (count choices))
|
||||
(< index 1))
|
||||
; try again
|
||||
(recur prompt choices)
|
||||
; ok
|
||||
(nth choices (dec index)))))))
|
||||
|
||||
(println "You chose: "
|
||||
(menu "Which is from the three pigs: "
|
||||
["fee fie" "huff and puff" "mirror mirror" "tick tock"]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue