blob: f9c5c267edd8bd5e16cfae6693daa570874252d6 (
plain) (
blame)
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
|
(import r7rs
(prefix (hascheme base) ha:)
(hascheme eager)
(srfi 64))
(cond-expand
(chicken-5 (test-runner-current (test-runner-create)))
(else))
(ha:define
(hascheme-natural-numbers)
(ha:let loop ((i 0)) (ha:seq i (ha:cons i (loop (ha:+ i 1))))))
(ha:define (square-of-list list) (ha:map ha:square list))
(test-group "lists"
(test-assert
"cons is lazy, car"
(force (ha:car (ha:cons #t (ha:error "boom")))))
(test-assert
"cons is lazy, cdr"
(guard (x ((equal? (force (error-object-message x)) "boom") #t)
(else #f))
(force (ha:cdr (ha:cons #f (ha:error "boom"))))
#f))
(test-equal
1000
(force (ha:list-ref (hascheme-natural-numbers) 1000)))
(let ((flag '()))
(test-equal
"map is lazy"
'(1000)
(begin
(force (ha:list-ref (ha:map (ha:lambda (x) (set! flag
(cons (force x) flag)))
(hascheme-natural-numbers))
1000))
flag)))
(test-equal "runs in bounded space"
(square 1000)
(force (ha:list-ref (square-of-list (hascheme-natural-numbers))
1000))))
|