jrfang%peruvian.utah.edu@cs.utah.edu (05/31/90)
Hi, We have an assignment in this quarter about backward chaining. I try to use Turbo Prolog, but it seems has many troubles in it. /* Things that can be asked of the user are recorded as: askable(<goal>). Rules are recorded as: rule(<name>, <lhs-goal>, [<rhs-goal-1>, ..., <rhs-goal-n>]). Queries are written as: [<goal-1>, ..., <goal-n>] */ /* The empty query is always successful. */ backward([]). /* A singleton query can be answered by the user if it is askable. */ backward([Goal]) :- askable(Goal), askUser(Goal). /* A singleton query can be expanded if a rule is applicable. */ backward([Goal]) :- rule(_, Goal, Condition), backward(Condition). /* A compound query can be solved recursively. */ backward([Goal | Goals]) :- \+(Goals = []), backward([Goal]), backward(Goals). /* We assume that Goal is variable free. This succeeds if the user says yes, explains and retries if the user says why, and fails otherwise. */ askUser(Goal) :- write('Is this true: '), write(Goal), nl, read(X), (X = yes; (X = why, write('Unknown'), nl, askUser(Goal, Why))). /* Now some sample program rules. */ rule(r1, isMammal(X), [hasHair(X), warmBlooded(X)]). rule(r2, isBird(X), [hasFeathers(X), laysEggs(X)]). rule(r4, isCat(X), [isMammal(X), purrs(X)]). rule(r5, isRobin(X), [isBird(X), canFly(X)]). rule(r5, isEmu(X), [isBird(X), cantFly(X)]). askable(hasHair(_)). askable(warmBlooded(_)). askable(hasFeathers(_)). askable(laysEggs(_)). askable(purrs(_)). askable(canFly(_)). askable(cantFly(_)). How can I transfer the clause like rule(r1, isMammal(X), [hasHair(X), warmBlooded(X)]). into Turbo Prolog? It seems in Turbo Prolog does not have the form like (..[..[..]..]) (not list). Thank!!! --------