我可以安全地假设
时(gen-sym-map (gen-acct-num-sym @sym-count (gen-acct-nums 10)) 100.00)
执行我有一个懒惰的序列,还是gen-sym-map会在lazy-seq函数调用中返回结果映射?
(defn gen-acct-nums [range-end-idx]
(vec (range 10000 (+ 10000 range-end-idx 1))))
(defn random-acct-num [acct-nums]
(nth acct-nums (.nextInt random (count acct-nums))))
(defn gen-acct-num-sym [num-syms acct-nums]
(loop [snum num-syms acct-num-lis []]
(if (= snum 0)
acct-num-lis
(recur (dec snum) (conj acct-num-lis (random-acct-num acct-nums))))))
(defn gen-sym-map-day [acct-nums starting-bal]
(reduce
(fn [sym-map one-acct-num]
(let [trans (random-trans )
amt (random-amount )]
(conj sym-map { one-acct-num (vector trans amt starting-bal) } )))
{}
acct-nums))
(defn gen-sym-map [acct-nums starting-bal]
(loop [day-count-left @sym-day-count current-day 1 sym-map-local {}]
(if (= day-count-left 0)
sym-map-local
(recur (dec day-count-left) (inc current-day)
(conj sym-map-local {(gen-map-key current-day)
(gen-sym-map-day acct-nums starting-bal)} )))))
答案 0 :(得分:4)
在这种情况下你不得到一个懒惰的序列。
这是出于各种原因:
如果你想在Clojure中使用延迟序列,最简单的方法通常是根据产生map和filter等序列的高阶函数编写代码。大多数序列生成函数默认创建延迟序列。
如果你想构建一个懒惰的序列,你当然可以在lazy-seq中包装东西,但这需要以下内容:
lazy-seq的经典用法是使用一些高阶函数和递归来定义(可能是无限的)惰性序列,例如:如下:
(def fibs (concat [1 2] (lazy-seq (map + fibs (next fibs)))))