Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 16, 2019 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/755e119ba488b246f766402882df053f to your computer and use it in GitHub Desktop.
Save chelseatroy/755e119ba488b246f766402882df053f to your computer and use it in GitHub Desktop.
amb procedures
(define (amb? sexp)
(and (pair? sexp) (eq? (car sexp) 'amb)))
(define (amb-choices sexp) (cdr sexp))
(define (seval-amb sexp succeed fail env)
(define (try-next choices)
(if (null? choices)
(fail)
(seval (car choices) succeed
(lambda () (try-next (cdr choices))) env)
)
)
(try-next (amb-choices sexp))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment