Commits

Anonymous committed 52618ca

Implement lazy-repeat and lazy-repeatedly

  • Participants
  • Parent commits 6c31554

Comments (0)

Files changed (2)

  lazy-head lazy-tail
  lazy-take lazy-drop lazy-ref
  lazy-map lazy-filter lazy-each
- lazy-numbers
+ lazy-numbers lazy-repeat lazy-repeatedly
  realized-lazy-seq
  input-port->lazy-seq)
 
             '()
             (cons datum (loop)))))))
 
+(define (lazy-repeat x)
+  (lazy-seq (cons x (lazy-repeat x))))
+
+(define (lazy-repeatedly f)
+  (lazy-seq (cons (f) (lazy-repeatedly f))))
+
 )
              (lazy-numbers count: 5))
   (test sum (fold + 0 (iota 5))))
 
+(test-group "lazy-repeat"
+  (test '(x x x x) (lazy-seq->list (lazy-take 4 (lazy-repeat 'x)))))
+
+(test-group "lazy-repeatedly"
+  (test 10 (lazy-ref 9 (lazy-repeatedly (let ((n 0)) (lambda () (set! n (+ n 1)) n))))))
+
 (test-exit)