Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; zadanie 1
- (define (st-app2 f . xs)
- (define (helper lst s rs)
- (if (null? lst)
- (cons (reverse rs) s)
- (let ([rx ((car lst) s)])
- (helper (cdr lst) (res-state rx) (cons (res-val rx) rs)))))
- (lambda (s)
- (let ([rx (helper xs s '())])
- (res (apply f (car rx))
- (cdr rx)))))
- (define (rename3 t)
- (define (rename-st t)
- (cond [(leaf? t)
- (st-app2 (lambda (x y) x)
- get-st
- (modify-st inc))]
- [(node? t)
- (st-app2 node
- (rename-st (node-left t))
- (rename-st (node-right t)))]))
- (res-val ((rename-st t) 0)))
- ;; zadanie 2
- ;; generator liczb pseudolosowych
- (define (rand max)
- (lambda (i)
- (let ([v (modulo (+ (* 1103515245 i) 12345) (expt 2 32))])
- (res (modulo v max) v))))
- (define (rename-rand t)
- (define (rename-st t)
- (cond [(leaf? t)
- (st-app (lambda (x y) x)
- get-st
- (rand 100))]
- [(node? t)
- (st-app node
- (rename-st (node-left t))
- (rename-st (node-right t)))]))
- (res-val ((rename-st t) 0)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement