Prolog "Not together in source file" 和 "Singleton Variable" 错误

Prolog "Not together in source file" and "Singleton Variable" errors

我是 prolog 的新手并且制作了一个简单的 prolog 程序,我不断收到这些错误,还有更多但我认为不需要全部关闭它们,因为它们都是一样的:

    Clauses of door/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:27:
      Clauses of room/1 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:28:
    Clauses of door/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:34:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:36:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:37:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:38:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:40:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:42:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:49:
    Clauses of location/2 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:51:
    Singleton variables: [North,Table]
Warning: c:/users/hani cassidy/desktop/test/test.pl:51:
    Clauses of location/3 are not together in the source-file
Warning: c:/users/hani cassidy/desktop/test/test.pl:52:
    Singleton variables: [East,Table]
Warning: c:/users/hani cassidy/desktop/test/test.pl:53:
    Singleton variables: [South,Table]
Warning: c:/users/hani cassidy/desktop/test/test.pl:54:
    Singleton variables: [Table] 
Warning: c:/users/hani cassidy/desktop/test/test.pl:55:
    Singleton variables: [Centre,Table]
ERROR: c:/users/hani cassidy/desktop/test/test.pl:59:20: Syntax error: Operator expected
Warning: c:/users/hani cassidy/desktop/test/test.pl:67:

我注意到它们都是一样的,所以我知道每个人都会犯同样的错误,但是我只是不知道我是序言的新手,下面是我的代码的一部分: 门(大厅,卧室A)。 门(大厅,卧室B)。 门(大厅,客厅厨房)。

%Bedroom B – Hall
room(bedroomB).
door(bedroomB, hall).

%Sitting room / Kitchen – Hall, Bathroom
room(sittingroomkitchen).
door(sittingroomkitchen, hall).
door(sittingroomkitchen, bathroom).

%Bathroom – Sitting room/Kitchen
room(bathroom).
door(bathroom, sittingroomkitchen).

%Each Bedroom = Desk, Bed, Pillow, Duvet, Wardrobe
location(bed, bedroomA).
location(pillow, bed, bedroomA).
location(duvet, bed, bedroomA).
location(wardrobe, bedroomA).
location(desk, bedroomA).
location(phone, underPillow, bedroomA).
location(bed, bedroomB).
location(pillow, bed, bedroomB).

如果需要更多信息,我可以提供,这只是一个片段。

关于 "Clauses of ... are not together in the source-file" 警告,大多数(如果不是全部)Prolog 系统都希望同一谓词的子句一起出现在源文件中。解决方案是为子句分散在源文件中的谓词添加 discontiguous/1 指令,或者将它们的所有子句移动到一起。对于第一个解决方案,在这些谓词的任何子句之前写:

:- discontiguous([
    room/1, door/2, location/2, location/3
]).

不连续的谓词有时是由于代码中的拼写错误造成的(例如,不小心忘记了子句头部的参数),永远不应忽略。

如果您遇到这样的问题,请尝试一个接一个地组合所有相同的谓词。

例如;

你应该这样写

female(pam).
female(liz).
female(pat).
female(ann).
male(jim).
male(tom).
male(bob).

而不是

`female(pam).
 female(liz).
 male(jim).
 female(ann).
 male(tom).
 female(pat).
 male(bob).`

请注意,order 两者并不相同。

相同的谓词依次传递。