I'm new to Clojure and was hoping SO could help me out here:
;; a loop to collect data
(defn read-multiple []
(def inputs (list))
(loop [ins inputs]
(def input (read-val ">"))
(if (not= input "0")
(recur (conj ins input)))
(i-would-like-to-return-something-when-the-loop-terminates)))
How do I, after collecting the input, get a list of all the input collected thus far?
the return value of the loop will be the retrun value of the if statement
(loop [ins inputs]
(def input (read-val ">"))
(if (not= input "0")
(recur (conj ins input))
return-value-goes-here))
and replace def
with let
for binding locals
(loop [ins inputs]
(let [input (read-val ">")]
(if (not= input "0")
(recur (conj ins input))
return-value-goes-here)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With