Repeated execution of clojure lazy seq

I am trying to implement Clojures lazyseq as a training exercise, I am trying to figure out what happens in LazySeq.java,

https://github.com/richhickey/clojure/blob/20090320/src/jvm/clojure/lang/LazySeq.java

this branch does not assume that it has chunking behavior, so I think it should call fn every time it is called first, but I can’t understand what the call does seq? more specifically, the next line,

s = RT.seq(fn.invoke());
+3
source share
1 answer

lazy-seq . , , . - - lazy-seq :

(defn simple-lazy-seq*
  [seq-producing-fn]
  (reify
    clojure.lang.Sequential
    clojure.lang.Seqable
    (seq [this] (seq (seq-producing-fn)))))

(defmacro simple-lazy-seq
  [& body]
  `(simple-lazy-seq* (fn [] ~@body)))

lazy-seq ISeq, .

: Java.

static Seqable lazy_seq(IFn seq_generating_fn) {
    return new Seqable() {
        ISeq seq() {
            return RT.seq(seq_generating_fn.invoke());
        }
    }
}

YourClass.lazy_seq(new IFn() {
    Object invoke() {
        return thing.returning_the_seq();
    }
});

, , . , . . thing final IIRC. Java.

+1

All Articles