Commits

Anonymous committed 8a5bcc2

Implement lazy-iterate

  • Participants
  • Parent commits 15ecac5

Comments (0)

Files changed (2)

 
 (lazy-seq make-lazy-seq
  lazy-seq? lazy-seq-realized?
- lazy-null lazy-null?
+ lazy-null lazy-null? realized-lazy-seq
  lazy-seq->list list->lazy-seq
  lazy-head lazy-tail lazy-append
  lazy-take lazy-drop lazy-ref
  lazy-map lazy-filter lazy-each
- lazy-numbers lazy-repeat lazy-repeatedly
- realized-lazy-seq 
- input-port->lazy-seq)
+ lazy-iterate lazy-repeat lazy-repeatedly
+ lazy-numbers input-port->lazy-seq)
 
 (import chicken scheme)
 (use srfi-1 extras)
                   (cons (lazy-head seq)
                         (loop2 (lazy-tail seq))))))))))
 
+(define (lazy-iterate f x)
+  (lazy-seq
+    (cons x (lazy-iterate f (f x)))))
+
 )
                                    (lazy-numbers count: 2)
                                    (lazy-numbers start: 5)))))
 
+(test-group "lazy-iterate"
+  (test '(2 4 8 16)
+        (lazy-seq->list
+         (lazy-take 4 (lazy-iterate (lambda (x) (* x 2)) 2)))))
+
 (test-exit)