从循环中返回一个值

low*_*key 3 clojure

我是 Clojure 的新手,希望 SO 可以帮助我:

;; 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)))
Run Code Online (Sandbox Code Playgroud)

在收集输入后,我如何获得迄今为止收集的所有输入的列表?

Art*_*ldt 5

循环的返回值将是 if 语句的重新运行值

 (loop [ins inputs]
   (def input (read-val ">"))
   (if (not= input "0")
     (recur (conj ins input))
     return-value-goes-here))
Run Code Online (Sandbox Code Playgroud)

和替换deflet的结合当地人

(loop [ins inputs]
 (let [input (read-val ">")]
  (if (not= input "0")
    (recur (conj ins input))
    return-value-goes-here)))
Run Code Online (Sandbox Code Playgroud)