Reputation: 100
The following code
itD(Start, End, Distance, Max) :-
Distance < Max,
newDistance is Distance+1,
itD(Start, End, newDistance, Max).
Gives me a very strange fail.
2 2 Call: 0<15 ?
2 2 Exit: 0<15 ?
3 2 Call: newDistance is 0+1 ?
3 2 Fail: newDistance is 0+1 ?
Which I really don't understand. Since I'm using really basic arithmetics.
| ?- Distance is 1, NewDistance is Distance+1.
Distance = 1
NewDistance = 2
yes
As you can see I have no issues what so ever writing the same operation in the console.
I would be really glad if someone could help me figure this strange arithmetic issue.
Upvotes: 0
Views: 84
Reputation: 100
Just the second after I posted this i realized that variables in prolog need to start with a capital letter, I guess that's a quite common mistake for someone new in Prolog.
Hope this will help someone out in the future.
Upvotes: 2