Implement till 3.66
This commit is contained in:
29
util.scm
29
util.scm
@@ -68,4 +68,33 @@
|
||||
(display x)
|
||||
(newline))
|
||||
|
||||
(define (take n xs)
|
||||
(if (= n 0)
|
||||
'()
|
||||
(cons (stream-car xs)
|
||||
(take (- n 1) (stream-cdr xs)))))
|
||||
|
||||
(define (display-stream s)
|
||||
(stream-for-each display-line s))
|
||||
|
||||
(define (show x)
|
||||
(display-line x)
|
||||
x)
|
||||
|
||||
(define (stream-ref s n)
|
||||
(if (= n 0)
|
||||
(stream-car s)
|
||||
(stream-ref (stream-cdr s) (- n 1))))
|
||||
|
||||
(define (partial-sums xs)
|
||||
(cons-stream (stream-car xs)
|
||||
(add-streams (partial-sums xs)
|
||||
(stream-cdr xs))))
|
||||
|
||||
(define (scale-stream stream factor)
|
||||
(stream-map (lambda (x) (* x factor)) stream))
|
||||
|
||||
(define (add-streams s1 s2)
|
||||
(stream-map + s1 s2))
|
||||
|
||||
'util-loaded
|
||||
|
||||
Reference in New Issue
Block a user