刚开始在 Prolog 中编程。我写了几个条款。
predicates
parent(symbol,symbol)
male(symbol)
female(symbol)
mother(symbol,symbol)
father(symbol,symbol)
brother(symbol,symbol)
sister(symbol,symbol)
uncle(symbol,symbol)
clauses
parent(arthur,fred).
parent(arthur,george).
parent(arthur,bill).
parent(arthur,percy).
parent(arthur,ginny).
parent(arthur,ron).
parent(arthur,charlie).
parent(molly,fred).
parent(molly,george).
parent(molly,bill).
parent(molly,percy).
parent(molly,ginny).
parent(molly,ron).
parent(molly,charlie).
parent(rowling,arthur).
parent(rowling,james).
parent(james,harry).
parent(lily,harry).
female(molly).
female(ginny).
female(lily).
female(rowling).
male(X) if not(female(X)).
brother(X,Y) if male(Y),X<>Y,brother(Y,X).
brother(X,Y) if X<>Y,parent(Z,X),parent(Z,Y),male(X).
mother(X,Y) if parent(X,Y),female(X).
father(X,Y) if parent(X,Y),male(X).
sister(X,Y) if parent(Z,X),parent(Z,Y),female(X),X<>Y.
uncle(X,Y) if parent(Z,Y),brother(X,Z).
但是当我试图问问题时
brother(X,james)
它在X <> Y 行的表达式中显示自由变量
brother(X,Y) if male(Y),X<>Y,brother(Y,X).
我无法追踪代码有什么问题