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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
NPRbeing the new value for N (whereNPR is N + R).