(require (planet "chain.rkt" ("slowthought" "my-planet.plt" 1 1)))
Forward chaining is an artificial intelligence technique that enables deductive reasoning.
|(forward-chain [precedent consequent ...] ...)|
provides a ’cond like syntax to implement forward chaining. Each precedent is evaluated at least once (barring back-chain-like escapes). Each set of consequences is evaluated no more than once. Example:
|[#f (display "Nobody likes me!")|
|[#t (display "Hello, World!")|
|; A common idiom is to stop processing when some goal is reached|
|(let [(red #t)|
|[(and red white blue)|
|(display "All American")|
|[(and red green blue)|
|(set! white #t)]|
|[#t (display "Should never get here.")|
In the above example, nobody knows that nobody likes me. (display "Hello, World") is executed once. (display "All American")i s skipped on the first pass, but when it’s found that red, green, and blue make white later in the rule list, (and red white blue) is reevaluated, and the point of laboring on is moot!