temperature(thessaloniki,january,24,1).
temperature(thessaloniki,january,25,-2).
temperature(katerini,january,24,3).
temperature(loutsa,feb,25,1).
temp([],[],[]).
temp([H|T],L2,L3) :-
temp(T,L4,L5),
temperature(H,january,_,Te),
Te>0,
append([H],L4,L2),
L3=L5.
temp([H|T],L2,L3) :-
temp(T,L4,L5),
temperature(H,january,25,Te),
Te<0,
append([H],L5,L3),
L2=L4.
temp([H|T],L2,L3) :-
temp(T,L4,L5),
L2=L4,
L3=L5.
We have towns with temperatures and dates. And we need to add them to the correct list. I think the rules is right but when I run it with TkEclipse I get this:
?- temp([thessaloniki, thessaloniki, katerini, loutsa], L2, L3).
L2 = [thessaloniki, thessaloniki, katerini]
L3 = []
and as I watched at the tracer of program take only the first temperature(thessaloniki,january,24,1).
2 times and not the second one temperature(thessaloniki,january,25,-2).
If change the name of the second to thessaloniki2 run ok but the exercise gives it with the same name.