Trying to get experience working with lazy-seq, after several earlier
successful attempts, I was implementing a lazy infinite Fibonacci
sequence as a lazy-seq (having already implemented it in a greedy way
before), and it wasn't working.  I remembered that I had seen a
working example somewhere, Googled it, and up it came.

And that version works, but mine, while very similar (and I've
modified the two versions to make them even more similar except for
the problem)...mine fails:

;; works: (take 7 fib-seq-works) => (1 1 2 3 5 8 13)
(def fib-seq-works
  ((fn rfib [a b]
     (lazy-seq (cons a (rfib b (+ a b)))))
   1 1))

;; fails: (take 7 fib-seq-fails) => IllegalArgumentException: Don't
know how to create ISeq from: user$fib-seq-fails
(defn fib-seq-fails
  ([] (fib-seq-fails 1 1))

  ([a b]
     (lazy-seq (cons a (fib-seq-fails b (+ a b))))))

Any clue as to why the second version fails? I have made about six
attempts, and some work great, and some fail in this same manner.
What is wrong with the "fails" version?

(This is with with clojure "1.3.0")

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to