;; For stream programming section 3.5 ;; We use the R5RS define force and delay which are slightly ;; different from the force and delay defined in the book: ;; delay (aka make-promise) handles recursive forcing. (define the-empty-stream '()) (define stream-null? null?) (define stream-car car) (define (stream-cdr s) (force (cdr s))) (define-syntax cons-stream (syntax-rules () ((_ head tail) (cons head (delay tail))))) (load "plotizing.ss") (load "heartbeat.ss") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 1 (define sums 'todo) ;; test (define (add-streams2 s1 s2) 'todo) ;; test (define prods 'todo) ;; test (define (bounded-random-stream L U) 'todo) ;; test ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 2: Nothing to hand in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 3 (define (binarize s t) 'todo) ; test ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 4 (define (peak-positions s) 'todo) ; test ;; part b explanation ; Optional part b code (define (peak-positions2 n s) 'todo) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 5 (define (peak-spacing s) 'todo) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 6 (define (check-regularity s tolerance n receiver) 'todo) ;;; provided test code (define heartbeat (get-patient-heart-signal)) (define start-of-monitoring (peak-spacing (peak-positions2 1000 (binarize heartbeat 5)))) ; get some visual idea of irregularity ;(plot-stream ; (map-stream (lambda (x) (- x (stream-car start-of-monitoring))) ; start-of-monitoring) ; 2 141) ; get a printout ; (limited-print-stream 141 start-of-monitoring) ; now get the automated report (define tolerance 2) ; durations can be at most 1 off (define runlength 7) (define (check-some s n) (if (= n 0) 'done (check-regularity s tolerance runlength (lambda (s regular) (display (if regular 'regular 'irregular)) (display " ") (check-some s (- n 1)))))) ;(check-some start-of-monitoring 20) ; depends on heartbeaet... ;(check-some ones 20) ; should be all regular ;(check-some (bounded-random-stream 3 6) 20) ;all regular with high probability ;(set! runlength 2) ;(check-some (bounded-random-stream 3 6) 20) ; mix of regular, irregular ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Problem 7 ;; a ;; I recommend an auxilliary procedure taking a number of patients and ;; having patient-stream call the auxilliary procedure with an arbitrary ;; number of your choosing (define patient-stream 'todo) ;; b (define (stream-nth n s) 'todo) ;;c (define (stream-nth-tail n s) 'todo) ;; d (define (stream-nth-action f) 'todo) (define stream-nth (stream-nth-action 'todo)) (define stream-nth-tail (stream-nth-action 'todo)) ;; e (define (plot-heartbeats s n) 'todo) ;; f (define (monitor patient-stream tolerance n) 'todo)