Returning a list of inputs from a loop
;; a helper function to display a prompt
(def read-val [name]
(println (str name ": "))
(read-line))
;; reads lines until 0 is entered
(defn read-multiple []
(loop [inputs []]
(def input (read-val ">"))
(if (= input "0")
inputs
(recur (conj inputs input)))))
;; prints the collected inputs
(println (read-multiple))
Written by Joshua Moore
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Clojure
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#