I'm writing a rule that is to go from one node to a destination in a cyclic graph. In order to do this I need the rule to remember the visited nodes as it moves through the graph. My problem is that I want to be able to call it like this:
?- routeToDestination(startNode, destinationNode, Path)
and get the path through the graph stored in the Path variable. When I try to append the nodes in the Path variable I'm having some troubles with it not being initiated as a list. My rule looks like this so far:
routeToDestination(Destination, Destination, Path).
routeToDestination(Origin, Destination, Path):-
link(Origin, Via),
\+ visited(Via, Path),
appendEnd(Path, Via, Result),
routeToDestination(Via, Destination, Result).
Here link is a number of facts that tell where there are connections from Via (i.e. I check to which nodes I can go from Via), visited checks if the element is already in the Path (don't want to visit twice), appendEnd is the typical append function (http://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpages/lists.html):
append([],List,List).
append([Head|Tail],List2,[Head|Result]):-
append(Tail,List2,Result).
Whenever I try to make the call it looks like the append function fails because Path is a variable and not a list. Is there a workaround for this, or am I thinking the wrong way?