Commits

Moritz Heidkamp  committed 6c31554

Make lazy-filter (slightly) more efficient

  • Participants
  • Parent commits 5320e69

Comments (0)

Files changed (1)

File lazy-seq.scm

               (apply lazy-map proc (map lazy-tail seqs))))))
 
 (define (lazy-filter pred? seq)
-  (lazy-seq
-    (if (lazy-null? seq)
-        '()
-        (let ((head (lazy-head seq))
-              (tail (lazy-filter pred? (lazy-tail seq))))
-          (if (pred? head)
-              (cons head tail)
-              tail)))))
+  (let loop ((seq seq))
+    (lazy-seq
+      (if (lazy-null? seq)
+          '()
+          (let ((head (lazy-head seq))
+                (tail (loop (lazy-tail seq))))
+            (if (pred? head)
+                (cons head tail)
+                tail))))))
 
 (define (lazy-ref n seq)
   (if (zero? n)