增加堆栈大小时,prolog会出现语法错误

时间:2014-07-02 09:03:22

标签: prolog turbo-prolog zebra-puzzle

尝试用prolog解决拼图任务并遇到一些问题。

1002 Stack Overflow. Re-configure with Setup if necessary.

所以,我试图在设置和再次运行程序中增加堆栈大小。 但它会导致另一个错误:Syntax error on line... 错误行与运算符"不是"在谓词中。

这是我的代码:

domains

 age = integer
 childname,ffood,fear = string
 child = child(childname,age,ffood,fear)
 children = child*

predicates
 solve
 name(child,childname)
 fear(child,fear)
 age(child,age)
 ffood(child,ffood)
 keys(children)
 solution(children)
 elder(child)
 member(children,child)
 structure(children)

clauses

 member([X|_],X).
 member([_|SP],X):-member(SP,X).    

 name(child(A,_,_,_),A).
 age(child(_,A,_,_),A).
 ffood(child(_,_,A,_),A).
 fear(child(_,_,_,A),A).

structure([child("Dima",_,_,_),child("Kate",_,_,_),child("Misha",_,_,_),child("Sveta",_,_,_),child("Ura",_,_,_)]).

elder(child(_,A,_,_)):-A=7;A=8.

solve:-structure(Children),keys(Children),solution(Children).

keys(Struct):-
member(Struct,child(_,4,_,_)),
member(Struct,child(_,5,_,_)),
member(Struct,child(_,6,_,_),
member(Struct,child(_,7,_,_),
member(Struct,child(_,8,_,_)),
member(Struct,child(_,_,"Banana",_),
member(Struct,child(_,_,"Icecream",_),
member(Struct,child(_,_,"Pizza",_),
member(Struct,child(_,_,"Pasta",_),
member(Struct,child(_,_,"Chocolate",_),
member(Struct,child(_,_,_,"Thunderstorm"),
member(Struct,child(_,_,_,"Spiders"),
member(Struct,child(_,_,_,"Ghosts"),
member(Struct,child(_,_,_,"Dogs"),
member(Struct,child(_,_,_,"Darkness"),
member(Struct,Child1),
name(Child1,"Kate"),
elder(Child1),
not(fear(Child1,"Darkness")),
not(ffood(Child1,"Chocolate")),
member(Struct,Child2),
name(Child2,"Sveta"),
elder(Child2),
not(fear(Child2,"Darkness")),
not(ffood(Child2,"Chocolate")),
ffood(Child2,"Pizza"),
not(fear(Child2,"Spiders")),
member(Struct,Child3),
age(Child3,5),
fear(Child3,"Ghosts"),
member(Struct,Child4),
age(Child4,6),
fear(Child4,"Thunderstorm"),
not(ffood(Child4,"Chocolate")),
not(ffood(Child4,"Pasta")),
member(Struct,Child5),
age(Child5,4),
ffood(Child5,"Banana"),
member(Struct,Child6),
age(Child6,8),
not(fear(Child6,"Dogs")),
member(Struct,Child7),
name(Child7,"Dima"),
not(age(Child7,5)),
not(fear(Child7,"Darkness")),
not(fear(Child7,"Spiders")),
not(ffood(Child7,"Banana")),
member(Struct,Child8),
name(Child8,"Misha"),
not(fear(Child8,"Darkness")),
not(fear(Child8,"Spiders")),
not(ffood(Child8,"Banana")).


solution (Children):-
    write ("Solve:"), write (Children).

goal

solve.

发现奇怪的这个prolog行为......也许有人有同样的问题?

1 个答案:

答案 0 :(得分:0)

我尝试使用SWI-Prolog重新格式化代码:

keys(Struct):-
    member(Struct,child(_,4,_,_)),
    member(Struct,child(_,5,_,_)),
    member(Struct,child(_,6,_,_),
           member(Struct,child(_,7,_,_),
              member(Struct,child(_,8,_,_)),
              member(Struct,child(_,_,"Banana",_),
...

似乎你错过了一些括号...... 经过明显的修正后,我得到了

?- solve.
Solve:[child(Dima,6,Icecream,Thunderstorm),child(Kate,8,Pasta,Spiders),child(Misha,5,Chocolate,Ghosts),child(Sveta,7,Pizza,Dogs),child(Ura,4,Banana,Darkness)]
true .