;;; deduce.scm Dave Reed ;;; ;;; This program implements a simple logical deduction system, based on ;;; the Prolog model. Knowledge is represented as a list of facts and ;;; rules, and the deduce function attempt to deduce a particular goal ;;; from that knowledge (using a goal reduction strategy). As is, the ;;; rules may not contain variables. ;;; (define KNOWLEDGE '((itRains <-- ) (isCold <-- ) (isCold <-- itSnows) (getSick <-- isCold getWet) (getWet <-- itRains))) (define (deduce goal known) (define (deduce-any goal-lists) (cond ((null? goal-lists) #f) ((null? (car goal-lists)) #t) (else (deduce-any (append (extend (car goal-lists) known) (cdr goal-lists)))))) (define (extend anded-goals known-step) (cond ((null? known-step) '()) ((equal? (car anded-goals) (caar known-step)) (cons (append (cddar known-step) (cdr anded-goals)) (extend anded-goals (cdr known-step)))) (else (extend anded-goals (cdr known-step))))) (if (list? goal) (deduce-any (list goal)) (deduce-any (list (list goal)))))