Here's a REPL session, wherein I try to use realized? on a
lazy-seq.
Clojure 1.3.0
Define the lazy-seq:
user= (def naturals (iterate inc 0))
#'user/naturals
Force realization of the first 1 + 123456 elements:
user= (time (nth naturals 123456))
Elapsed time: 481.349 msecs
123456
George Kangas gwkan...@gmail.com writes:
Now I try to use realized? on 123456th element:
user= (realized? (nth naturals 123456))
ClassCastException java.lang.Long cannot be cast to
clojure.lang.IPending clojure.core/realized? (core.clj:6505)
Hm, that's strange indeed. I also get
Can't you write that function yourself?
(defn realized-length [xs]
(loop [n 0 xs xs]
(if (realized? xs)
(recur (inc n) (rest xs))
n)))
drop returns a new lazy sequence, with no realized elements, so
naturally you can't ask if the sequence under it is realized. If you
want to
On Oct 7, 5:02 pm, Alan Malloy a...@malloys.org wrote:
Can't you write that function yourself?
(defn realized-length [xs]
(loop [n 0 xs xs]
(if (realized? xs)
(recur (inc n) (rest xs))
n)))
Thanks, Alan!
drop returns a new lazy sequence, with no realized elements,
I