-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0.util.scm
56 lines (47 loc) · 1.39 KB
/
0.util.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(define (print . vals)
(newline)
(for-each (lambda (x) (display x)
(display " "))
vals))
(define (global-eval exp)
(eval exp user-initial-environment))
(define (eval-and-print exps)
(for-each print
(map global-eval
exps)))
(define (test x y)
(if (equal? x y)
(print 'pass)
(error 'ne: x y)))
(define (within-delta? actual guess delta)
(< (abs (- guess actual))
delta))
(define (random-in-range low high)
(let ((range (- high low)))
(+ low (random range))))
(define (elapsed func)
(let ((current-time (runtime)))
(func)
(/ (round (* (- (runtime) current-time) 100)) 100)))
(define (repeat func trials)
(if (> trials 0)
(let ((return-value (func)))
(print return-value)
(repeat func (- trials 1)))))
(define (wait t)
(define (get-current-time)
(internal-time/ticks->seconds (real-time-clock)))
(let ((start-time (get-current-time)))
(define (loop)
(if (> t (* (- (get-current-time) start-time)))
(loop)))
(loop)))
(define (until stream condition then-what timeout)
(let loop ((stream stream)
(time-left timeout))
(if (zero? time-left) 'timeout
(let ((result (stream-car stream)))
(if (or (null? stream)
(condition result)) (then-what stream)
(loop (stream-cdr stream)
(- time-left 1)))))))