Exercise 3.81

Not sure if this works. Cannot test without rand-update:

1
2
3
4
5
6
7
8
9
10
11
(define (rand random-stream)
  (define (random-numbers initial-value)
    (cons-stream initial-value
                 (stream-map rand-update random-numbers)))
  (define (dispatch op)
    (cond ((eq? op 'generate) (random-numbers random-init))
          ((eq? op 'reset)
           (lambda (new-value)
             (random-numbers (stream-car (stream-filter (lambda (n) (= n new-value)) (random-numbers random-init))))))
           (else (error "Operation not found -- RAND" op))))
  dispatch)
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.

Tags: ,

Leave a Reply

CAPTCHA Image

Powered by WP Hashcash

Please wrap all source codes with [code][/code] tags.