prologturbo-prologzebra-puzzle

prolog get syntax error when increase stack size


Trying to solve the puzzle task with prolog and got some problems.

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

So, I've tried to increase stack size in setup and run program again. But it causes the other error: Syntax error on line... The error line is line with operator "not" in predicate.

Here is my code:

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.

Found strange this prolog behavior... maybe somebody had the same problem?


Solution

  • I tried to reformat your code with 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",_),
    ...
    

    seems you're missing some parenthesis... after the obvious correction, I get

    ?- 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 .