nanpng
Last Updated: February 25, 2016
·
462
· lowerkey

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))