Package "amb"


Version:
v1.0.0
Released:
1821 days ago
Maintainer:
---
Author:
Thomas Chust <chust@web.de>
Homepage:
---
Description:
The universal backtracking ambivalence operator.
Keywords:
logic
Package form:
(package*
 amb/v1.0.0
 (provide:
  (define (amb-fail))
  (define (amb-call . thunks))
  (define-macro (amb . exprs)
    (if (null? exprs)
        '(amb-fail)
        `(amb-call ,@(map (lambda (expr) `(lambda () ,expr)) exprs))))
  (define-macro (amb-assert cond?) `(or ,cond? (amb-fail)))
  (define* (call-with-amb-prompt thunk (failure _)))
  (define-macro (amb-find . body) `(call-with-amb-prompt (lambda () ,@body)))
  (define-macro (amb-collect . body)
    (let (($result (gensym 'result)))
      `(let ((,$result '()))
         (call-with-amb-prompt
          (lambda () (set! ,$result (cons (begin ,@body) ,$result)) (amb-fail))
          (lambda () (reverse ,$result)))))))
 (author: "Thomas Chust <chust@web.de>")
 (description: "The universal backtracking ambivalence operator.")
 (keywords: logic)
 (license: lgpl/v3.0)
 (cond-expand (gambit) (else (require: gensym/v1.0))))