Advertisement
overwater

Untitled

May 9th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.49 KB | None | 0 0
  1. (define (cycle-lists xs ys)
  2.   (define (get-stream-by-array xs)
  3.       (letrec ([f (lambda (x)
  4.                 (if (= x (- (length xs) 1))
  5.                     (cons (list-ref xs x) (lambda () (f 0)))
  6.                     (cons (list-ref xs x) (lambda () (f (+ x 1))))))])
  7.     (lambda () (f 0))))
  8.  
  9.   (define (cycle-streams s1 s2)
  10.     (lambda () (cons (cons (car (s1)) (car (s2))) (cycle-streams (cdr (s1)) (cdr (s2))))))
  11.  
  12.   (cycle-streams (get-stream-by-array xs) (get-stream-by-array ys)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement