0

Can someone explain how the following Prolog recursion works ?

findRoute(A,A,_). findRoute(A,C,Path) :- nextCnvZone(A,B), \+ member(B,Path), findRoute(B,C,[B|Path]). 

I can understand the second part but could not understand the first part i.e what is the first findRoute(A,A,_). doing ?

1

1 Answer 1

1

It is the part that stop the recursion, i.e. when the first parameter equals the second the recursion stops, and returns true through all of the recursion levels if it made it to that level.

In general, it has the rule that the first parameter equals the second. (check if true in case both variables are given, assign the value of the second to the first if the second is variable and the first is given, etc.)

?- findRoute(1, 1, 5). true ?- findRoute(1, 2, 5). false ?- findRoute(1, X, 5). X = 1 ?- findRoute(X, 2, 5). X = 2 
Sign up to request clarification or add additional context in comments.

1 Comment

can you elaborate the second paragraph .. the text inside the brackets.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.