Version: 5.0.1

1 Forward Chaining

  (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:
  (forward-chain
   [#f (display "Nobody likes me!")
       (newline)]
   [#t (display "Hello, World!")
       (newline)])
  ; A common idiom is to stop processing when some goal is reached
  (let [(red #t)
        (white 'unknown)
        (green #t)
        (blue #t)]
    (let/ec break-chain
      (forward-chain
       [(and red white blue)
        (display "All American")
        (break-chain)]
       [(and red green blue)
        (set! white #t)]
       [#t (display "Should never get here.")
           (error)])))
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!