Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instancing variables

Status
Not open for further replies.

Vhaerun

Programmer
Joined
Jun 6, 2009
Messages
1
Location
PT
hey everyone,
got a small problem with prolog : I'm trying to create a basic graph searching algorythm (I want to reach A from B and I have the rule connection(X,Y))and I think the variables aren't getting instanced:

%direct link between the 2
i_aux(Loc1, Loc2, Visited, [Loc2|Visited]) :-
connection(Loc1, Loc2).

%non direct link between the 2
i_aux(Loc1, Loc2, Visited, Path) :-
connection(Loc1, Loc_Aux),
Loc_Aux \== Loc1,
Loc_Aux \== Loc2,
\+member(Loc_Aux, Visited),
i_aux(Loc_aux, Loc2, [Loc_aux | Visited], Path).

When I call the i_aux recursively in "i_aux(Loc_aux, Loc2, [Loc_aux | Visited], Path)." it seems to update the visited variable poorly. When I trace it the list becomes a sequence of repetetive variables: How do I get it to become instanced :( ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top