非決定性計算を行うための「曖昧な(ambiguous)」特殊形式。 初出は John McCarthy. A Basis for a Mathematical Theory of Computation. In P Braffort and D Hirschberg, editors, Computer Programming and Formal Systems. North-Holland, 1967。
;; stack of cc.
(define fail '())
;;; nondeterminsm macro operator
(define-syntax amb
(syntax-rules ()
((_) ((pop! fail)))
((_ a) a)
((_ a b ...)
(call/cc
(lambda (cc)
(push! fail (lambda ()
(cc (amb b ...))))
a)))))
(define (solve)
(let ((i (amb 4 6 7))
(j (amb 5 8 11)))
(if (prime? (+ i j))
(list i j)
(amb))))
(print
(call/cc
(lambda (cc)
;; initial value for fail
(push! fail
(lambda ()
(cc 'no-choise)))
(solve))))
prime?はここにあります。Scheme:数遊び