Commits

Anonymous committed 726c83f

Implement input-port->lazy-seq

Comments (0)

Files changed (2)

  lazy-take lazy-drop lazy-ref
  lazy-map lazy-filter
  lazy-numbers
- realized-lazy-seq)
+ realized-lazy-seq
+ input-port->lazy-seq)
 
 (import chicken scheme)
 (use srfi-1 extras)
       (lazy-head seq)
       (lazy-ref (- n 1) (lazy-tail seq))))
 
+(define (input-port->lazy-seq port read)
+  (let loop ()
+    (lazy-seq
+      (let ((datum (read port)))
+        (if (eof-object? datum)
+            '()
+            (cons datum (loop)))))))
+
 )
 (test-group "lazy-ref"
   (test 3 (lazy-ref 3 (lazy-numbers))))
 
+(test-group "input-port->lazy-seq"
+  (test '(b c d)
+        (lazy-seq->list
+         (lazy-take
+          3 (lazy-tail
+             (input-port->lazy-seq
+              (open-input-string "a b c d e")
+              read)))))
+
+  (test-assert
+   (lazy-null?
+    (input-port->lazy-seq
+     (open-input-string "")
+     read))))
+
 (test-exit)