我在序言中编写了一个程序。
parent(Amy,John).
parent(Bob,John).
parent(John,Ben).
parent(Alice,Ben).
我在 Ubuntu 12.04 上使用 SWI-Prolog。当我将文件插入 swi-prolog 解释器时:
['example.pl']
我收到警告:
Warning: /home/mazix/example1.pl:1:
Singleton variables: [Amy,John]
Warning: /home/mazix/example1.pl:2:
Singleton variables: [Bob,John]
Warning: /home/mazix/example1.pl:3:
Singleton variables: [John,Ben]
Warning: /home/mazix/example1.pl:4:
Singleton variables: [Alice,Ben]
% example1.pl compiled 0.00 sec, 4 clauses
true.
这些是什么意思?底部的 true
是什么意思?我应该如何摆脱这个警告?
最佳答案
以大写字母开头的标识符是变量。如果您想要原子,请将它们用单引号引起来:
parent('Amy', 'John').
或以小写字母开头:
parent(amy, john).
“单例变量”是在其词法范围内仅出现一次的命名变量。实际上,这意味着您命名了它,但没有用它做任何有用的事情,因此会出现编译器警告。
关于prolog - 序言中的警告 : Singleton variables: [Alice, Ben],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21022381/