1 ;; done in Chicken scheme which has a builtin amb operator
2 ;; - can be installed with
3 ;; $ chicken-install amb
11 (define (an-element-of items)
12 (require (not (null? items)))
13 (amb (car items) (an-element-of (cdr items))))
15 (define (an-integer-between low high)
16 (let [(count (- high low))]
17 (let [(items (iota count low))]
18 (an-element-of items))))
20 (define (a-pythagorean-triple-between low high)
21 (let ((i (an-integer-between low high)))
22 (let ((j (an-integer-between i high)))
23 (let ((k (an-integer-between j high)))
24 (require (= (+ (* i i) (* j j)) (* k k)))
27 ;; another implementation
28 (define (an-integer-between-2 low high)
29 (require (< low high))
30 (amb low (an-integer-between-2 (+ low 1) high)))
33 (a-pythagorean-triple-between 1 20)