ランダムの無限の遅延シーケンスを生成するほぼ 2 つの同一のプログラム。最初はクラッシュしません。OutOfMemoryError 例外による 2 番目のクラッシュ。なんで?
;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)