;;
---------------------------------------------------------------------
;; using clojure.jar from source r1301
;;
;; I'm new to clojure and working from B7.0 of Programming Clojure.
;; This version still uses lazy-cons. Nevertheless I'm trying to grok
lazy-seq
;; as described here: http://clojure.org/lazy
;;
;; It seems I've not understood it because I'm getting
OutOfMemoryError
;; below and this surprises me
;; bog-standard iterative fib.
;; This works as expected
(defn fibi [n]
(loop [a 0, b 1, i n]
(if (<= i 0) a
(recur b (+ a b) (dec i)))))
;; (count (str (fibi 100000)))
;; --> 20899
;; my attempt to define a lazy fib sequence.
;; working? not so much.
(def fibl
((fn h [a b] (lazy-seq (cons a (h b (+ a b))))) 0 1))
;; (count (str (last (take 100000 fibl))))
;; --> java.lang.OutOfMemoryError: Java heap space
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---