Menu: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Clojure}}: fix verification and return type; add example invocation) |
||
Line 156: | Line 156: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
<lang |
<lang clojure>(defn menu [prompt choices] |
||
(if (empty? |
(if (empty? choices) |
||
"" |
"" |
||
(let [ |
(let [menutxt (apply str (interleave |
||
( |
(iterate inc 1) |
||
(map #(str \space % \newline) choices)))] |
|||
⚫ | |||
(map #(apply str (conj (seq (concat (seq %) "\n")) |
|||
(print prompt) |
|||
\space)) strs)))] |
|||
⚫ | |||
(print "Please enter a number: ") |
|||
(flush) |
(flush) |
||
(let [ |
(let [index (read-string (read-line))] |
||
; verify |
|||
input (read-string (read-line))] |
|||
(if (or |
(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"]))</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |