Next: , Previous: , Up: amb api   [Index]


1.4.1.3 Generating choices

The following bindings are exported by the library (vicare language-extensions amb).

Function: amb-thunk generator-thunk

Like amb but generate the next choice by evaluating a thunk. generator-thunk must be a thunk, which, when evaluated, returns the next choice; when no more choices are available generator-thunk must evaluate (amb).

#!r6rs
(import (vicare)
  (vicare language-extensions amb))

(define-values (empty? enqueue! dequeue!)
  (make-queue '(1 2 3 4)))

(define (generator)
  (if (empty?)
      (amb)
    (dequeue!)))

(with-ambiguous-choices
 (let ((R (amb-thunk generator)))
   (amb-assert (<= 3 R))
   R))
⇒ 3