我听说过它被称为流,也被称为无限列表,有时甚至被称为惰性序列.
以下模式的正确术语是什么?(Clojure代码如下)
(def first$ first)
(defn second$ [str]
(cond
(empty? str) ()
true ((first (rest str)))))
(defn stream-builder [next_ n]
(cons n (cons (fn [] (stream-builder next_ (next_ n))) ())))
(defn stream [str n]
(cond
(= 0 n) ()
true (cons (first$ str) (stream (second$ str) (- n 1)))))
(def odd
(stream-builder (fn [n]
(+ 2 n))1))
(println (stream odd 23))
> (1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45)