Reputation: 35
This is one of the assignment questions which I'm currently working on (yes, this is homework):
moveSouth([_],_,_Num,_Moves,_Time).
moveSouth(Members,SouthGrp,Num,Moves,Time) :-
member(X1/Y1,Members),
member(X2/Y2,Members),
X1 @< X2,
(((NewTime is Time+Y1),(Y1>=Y2));((NewTime is Time+Y2),(Y1<Y2))),
NewTime =< Num,
subtract(Members,[X1/Y1,X2/Y2],NewFam),
append(SouthGrp,[X1/Y1,X2/Y2],NewSouthGrp),
append(Moves,[X1+X2],NewMoves),
moveNorth(NewFam,NewSouthGrp,Num,NewMoves,NewTime).
moveNorth(Member,SouthGrp,Num,Moves,Time) :-
member(X1/Y1,SouthGrp),
NewTime is Time+Y1,
select(X1/Y1,SouthGrp,NewSouthGrp),
moveSouth([X1/Y1|Member],Num,NewSouthGrp,[Moves|X1],NewTime).
moveFamily(Name,Num,_Moves,_Time) :-
family(Name,Members),
moveSouth(Members,[],Num,[],0).
what I'm trying to do here is to move a List of names with property of Name/Time, to the south side, each time i can only move 2 members to the South, then needs to move one of the South members back to North.
now SWI-Prolog is giving me:
ERROR: =</2: Type error: `character' expected, found `mother/2'"
which I understand it means my types at =<
operator is/are wrong. What I don't understand is what caused this to happen.
PS: The fact I used was:
family(original, [father/1, mother/2, child/5, granny/10]).
The query I used was:
moveFamily(original,19,Moves,Time).
Upvotes: 2
Views: 2777
Reputation: 3407
The following line in your code assumes that X1/Y1
and X2/Y2
always occur next to each other (in that order) in the list of members:
subtract(Members, [X1/Y1,X2/Y2], NewFam),
But the way in which X1/Y1
and X2/Y2
are selected from the list of members shows that this need not be the case:
member(X1/Y1, Members),
member(X2/Y2, Members),
Another bug is in [Moves|X1]
, where X1
need not be a list at all.
Then the specific error that you asked your question about: in one call to moveSouth/4
you have swapped the second and third argument which leads to INTEGER =< LIST
.
Hope this helps!
Upvotes: 1