几乎 2 个相同的程序来生成无限的惰性随机序列。第一个不会崩溃。出现 OutOfMemoryError 异常的第二次崩溃。为什么?
;Return infinite lazy sequence of random numbers
(defn inf-rand[] (lazy-seq (cons (rand) (inf-rand))))
;Never returns. Burns the CPU but won't crash and lives forever.
(last (inf-rand))
但是以下崩溃很快:
;Return infinite lazy sequence of random numbers
(defn inf-rand[] (lazy-seq (cons (rand) (inf-rand))))
(def r1 (inf-rand))
;Crash with "OutOfMemoryError"
(last r1)