9 (error "no more choices!")))
11 (define (amb/thunks choices)
12 (let/cc k (set! failures (cons k failures)))
14 (let ([choice (first choices)])
15 (set! choices (rest choices))
17 (begin (set! failures (rest failures))
20 (define-syntax-rule (amb E ...)
21 (amb/thunks (list (lambda () E) ...)))
23 (define (assert condition)
24 (unless condition (fail)))
26 (define (collect/thunk n thunk)
29 (set! failures (list too-few))
30 (define result (thunk))
31 (set! results (cons result results))
33 (unless (zero? n) (fail)))
37 (define-syntax collect
40 [(_ N E) (collect/thunk N (lambda () E))]
41 ;; collect all results
42 [(_ E) (collect/thunk -1 (lambda () E))]))