I am new to Clojure and Lisp, but love it so far. I am currently trying to understand lazy-seq's and Clojure's ability to define infinite sequences. I have the following code:
(defn geometric
([] geometric 1)
([n] (cons n (lazy-seq (geometric (* n 1/2))))))
If I run:
(geometric)
in my REPL, it returns 1, as expected. However, if I run,
(take 10 (geometric))
I get the following error:
IllegalArgumentException Don't know how to create ISeq from:
java.lang.Long clojure.lang.RT.seqFrom
What I expect to get is:
(1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256 1/512)
Why am I getting this error? If I've understood correctly, one should be able to cons n to the lazy-sequence, and take should return the first ten values of the sequence, evaluated recursively.