This preview shows pages 1–3. Sign up to view the full content.
Teach Yourself Scheme in Fixnum Days [Go to first, previous, next page; contents; index]Chapter 14NondeterminismMcCarthy's nondeterministic operator amb[25, 4, 33] is as old as Lisp itself, although it is present in no Lisp. ambtakes zero or more expressions, and makes a nondeterministic (or ``ambiguous'') choice among them, preferring those choices that cause the program to converge meaningfully. Here we will explore an embedding of ambin Scheme that makes a depth-first selection of the ambiguous choices, and uses Scheme's control operator call/ccto backtrack for alternate choices. The result is an elegant backtracking strategy that can be used for searching problem spaces directly in Scheme without recourse to an extended language. The embedding recalls the continuation strategies used to implement Prolog-style logic programming [16, 7], but is sparer because the operator provided is much like a Scheme boolean operator, does not require special contexts for its use, and does not rely on linguistic infrastructure such as logic variables and unification.14.1 Description of ambAn accessible description of amband many example uses are found in the premier Scheme textbook SICP . Informally, ambtakes zero or more expressions and nondeterministicallyreturns the value of oneof them. Thus,(amb 1 2)may evaluate to 1 or2.ambcalled with noexpressions has no value to return, and is considered to fail. Thus,(amb)-->ERROR!!!amb tree exhausted(We will examine the wording of the error message later.)In particular, ambis required to return a value if at least one its subexpressions converges, ie, doesn't fail. Thus, (1 of 11) [2/6/2008 11:41:43 AM]
has intentionally blurred sections.
Sign up to view the full version.