Chapter 14 - Teach Yourself Scheme in Fixnum Days[Go to...

Info icon 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 14 Nondeterminism McCarthy's nondeterministic operator amb [ 25 , 4 , 33 ] is as old as Lisp itself, although it is present in no Lisp. amb takes 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 amb in Scheme that makes a depth-first selection of the ambiguous choices, and uses Scheme's control operator call/cc to 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 amb An accessible description of amb and many example uses are found in the premier Scheme textbook SICP [ 1 ]. Informally, amb takes zero or more expressions and nondeterministically returns the value of one of them. Thus, (amb 1 2) may evaluate to 1 or 2. amb called with no expressions 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, amb is 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]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.