Last active
August 29, 2015 14:08
-
-
Save PierreBdR/b37e5f17073f72370fc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (interleave-streams . ss) | |
(define (helper to-process processed) | |
(λ () | |
(if (null? to-process) | |
((helper (reverse processed) null)) | |
(let* ([next (car to-process)] | |
[pr (next)]) | |
(cons (car pr) (helper (cdr to-process) (cons (cdr pr) processed))))))) | |
(helper ss null)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Take a non-empty list and return a cyclic mlist | |
(define (list->cyclic-mlist lst) | |
(define (helper l) | |
(if (null? l) | |
#f | |
(let ([next (helper (cdr l))]) | |
(if next | |
(cons (mcons (car l) (car next)) (cdr next)) | |
(let ([val (mcons (car l) null)]) | |
(cons val val)))))) | |
(let ([pr (helper lst)]) | |
(begin | |
(set-mcdr! (cdr pr) (car pr)) | |
(car pr)))) | |
; Interleave n streams together | |
(define (interleave-streams2 . ss) | |
(define (helper to-process) | |
(thunk | |
(let ([pr ((mcar to-process))]) | |
(begin | |
(set-mcar! to-process (cdr pr)) | |
(cons (car pr) (helper (mcdr to-process))))))) | |
(helper (list->cyclic-mlist ss))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment