3

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

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

4

1 回答 1

5

循环的返回值将是 if 语句的返回值

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

并替换deflet绑定本地人

(loop [ins inputs]
 (let [input (read-val ">")]
  (if (not= input "0")
    (recur (conj ins input))
    return-value-goes-here)))
于 2012-06-28T18:20:54.103 回答