Menu: Difference between revisions

127 bytes added ,  14 years ago
→‎{{header|Clojure}}: fix verification and return type; add example invocation
No edit summary
(→‎{{header|Clojure}}: fix verification and return type; add example invocation)
Line 156:
 
=={{header|Clojure}}==
<lang lispclojure>(defn menu [strsprompt choices]
(if (empty? strschoices)
""
(let [menustrmenutxt (apply str (interleave
(applyiterate strinc 1)
(interleave (iteratemap #(+str 1\space % \newline) 1choices)))]
(println menustrmenutxt)
(map #(apply str (conj (seq (concat (seq %) "\n"))
(print prompt)
\space)) strs)))]
(println menustr)
(print "Please enter a number: ")
(flush)
(let [lenindex (countread-string strs(read-line) )]
; verify
input (read-string (read-line))]
(if (or (> input len) (< input len) (not (integer? input)index))
(> index (recurcount strschoices))
(println (nth strs (-< inputindex 1))))))))</lang>
; 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}}==
Anonymous user