summaryrefslogtreecommitdiff
path: root/sieve/my-streams.scm
blob: 6c0876244fd5338f29bc5c5f4eeb31f2886212b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

(library (my-streams)
    (export stream-ordered-diff stream-merge)
    (import (rnrs base) (srfi srfi-41))



(define-stream (stream-ordered-diff xstrm ystrm)
    (stream-match xstrm (() '()) ((x . xs)
        (stream-match ystrm (() xstrm) ((y . ys)
            (cond ((< x y) (stream-cons x (stream-ordered-diff xs ystrm)))
                  ((> x y) (stream-ordered-diff xstrm ys))
                  (else (stream-ordered-diff xs ys))))))))



(define-stream (stream-merge xstrm ystrm)
    (stream-match xstrm (() ystrm) ((x . xs)
        (stream-match ystrm (() xstrm) ((y . ys)
            (cond ((< x y) (stream-cons x (stream-merge xs ystrm)))
                  ((> x y) (stream-cons y (stream-merge xstrm ys)))
                  (else (stream-cons x (stream-merge xs ys)))))))))



)