为什么我的prolog文件只给我错误?

时间:2017-10-31 23:37:25

标签: prolog

我有以下.pl文件:

parent(Peter,Anne).
parent(Peter,Mark).

parent(Zara,Anne).
parent(Zara,Mark).


parent(Beatrice,Andrew).
parent(Beatrice,Sarah).

parent(Eugenie,Andrew).
parent(Eugenie,Sarah).


parent(Louise,Edward).
parent(Louise,Sophie).

parent(James,Edward).
parent(James,Sophie).

father(X,Y) :- male(Y),parent(Y,X).
mother(X,Y) :- female(X),parent(X,Y).
son(X,Y) :- male(X),parent(Y,X).
daughter(X,Y) :- female(X),parent(Y,X).
grandfather(X,Y) :- male(X),parent(X,Somebody),parent(Somebody,Y).
aunt(X,Y) :- female(X),sister(X,Mom),mother(Mom,Y).
aunt(X,Y) :- female(X),sister(X,Dad),father(Dad,Y).
sister(X,Y) :- female(X),parent(Par,X),parent(Par,Y), X \= Y.
uncle(X,Y) :- brother(X,Par),parent(Par,Y).
cousin(X,Y) :- uncle(Unc, X),father(Unc,Y).
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Y) :- parent(X,Somebody),ancestor(Somebody,Y).
brother(X,Y) :-  male(X),parent(Somebody,X),parent(Somebody,Y), X \= Y.

当我运行它时,我收到以下错误:

/home/cg/root/3832463/main.pg:4: warning: singleton variables [Peter,Anne] for parent/2
/home/cg/root/3832463/main.pg:5: warning: singleton variables [Peter,Mark] for parent/2
/home/cg/root/3832463/main.pg:7: warning: singleton variables [Zara,Anne] for parent/2
/home/cg/root/3832463/main.pg:8: warning: singleton variables [Zara,Mark] for parent/2
/home/cg/root/3832463/main.pg:11: warning: singleton variables [Beatrice,Andrew] for parent/2
/home/cg/root/3832463/main.pg:12: warning: singleton variables [Beatrice,Sarah] for parent/2
/home/cg/root/3832463/main.pg:14: warning: singleton variables [Eugenie,Andrew] for parent/2
/home/cg/root/3832463/main.pg:15: warning: singleton variables [Eugenie,Sarah] for parent/2
/home/cg/root/3832463/main.pg:18: warning: singleton variables [Louise,Edward] for parent/2
/home/cg/root/3832463/main.pg:19: warning: singleton variables [Louise,Sophie] for parent/2
/home/cg/root/3832463/main.pg:21: warning: singleton variables [James,Edward] for parent/2
/home/cg/root/3832463/main.pg:22: warning: singleton variables [James,Sophie] for parent/2
/home/cg/root/3832463/main.pg compiled, 36 lines read - 5049 bytes written, 10 ms
warning: /home/cg/root/3832463/main.pg:1: user directive caused exception: error(existence_error(procedure,main/0),load/1)
| ?- 
uncaught exception: error(syntax_error('user_input:1 (char:5) . or operator expected after expression'),read_term/3)
| ?- 

这是什么意思?

2 个答案:

答案 0 :(得分:3)

如果你的论证以资本开头,那么它就是一个变量。如果它是小写的,它就是一个原子。

变化:

parent(Peter,Anne).
parent(Peter,Mark).

为:

parent(peter,anne).
parent(peter,mark).

答案 1 :(得分:1)

人名通常是大写的。 在Prolog中,因为以大写字母开头的符号是变量,所以应引用它们:

parent('Peter','Anne').
etc...