Reputation: 500
I am writing a prolog code and in the middle I want to add 2 variables and store it in one of them I want to write some like this
N is N+R.
but it wont accept this can anyone tell me why and whats is the correct syntax Thank you
Upvotes: 2
Views: 90
Reputation: 370162
There is no correct syntax. N can't be equal to N+R (unless R is 0, in which case N will be N+R no matter what the value of N is). You can't update the value of a variable to something new the way you intend to. Prolog doesn't work like that.
Prolog doesn't have the concept of a variable having one value at one point in time and then having another value after a given statement executes. All you can ever do to a variable is restrict its possible values.
Obviously I don't know the big picture of what you're trying to do here, but perhaps you can achieve what you want by calling your predicate recursively with NPR
being the new value for N (where NPR is N + R
).
Upvotes: 2