Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (28 sloc) 958 Bytes
;; Example 3.56
#lang racket
(require racket/stream)
(define (scale-stream stream factor)
(stream-map (lambda (x) (* x factor)) stream))
(define (merge s1 s2)
(cond ((stream-empty? s1) s2)
((stream-empty? s2) s1)
(else
(let ((s1car (stream-first s1))
(s2car (stream-first s2)))
(cond ((< s1car s2car)
(stream-cons s1car (merge (stream-rest s1) s2)))
((> s1car s2car)
(stream-cons s2car (merge s1 (stream-rest s2))))
(else
(stream-cons s1car
(merge (stream-rest s1)
(stream-rest s2)))))))))
(define S (stream-cons 1 (merge (scale-stream S 2)
(merge (scale-stream S 3) (scale-stream S 5)))))
(stream-ref S 0)
(stream-ref S 1)
(stream-ref S 2)
(stream-ref S 3)
(stream-ref S 4)
(stream-ref S 5)
(stream-ref S 6)
Jump to Line
Something went wrong with that request. Please try again.