I am new to Prolog, I am trying to make a rule that gives me a given path from a node to another and also gives me the total weight of the path.
It runs perfectly but I get this warning: Singleton variables: [A]
and Singleton variables: [X,P] can someone help me how to solve this warning?
notIn(A,[]).
notIn(A,[H|T]):-
dif(A,H),
notIn(A,T).
start(X,Y,[X|Cs], P) :-
path(X,Y,[X],Cs, 0, P).
path(X,X,_,[], P, P).
path(X,Y,Visited,[Z|Cs], S, P) :-
connection(X,Z,W),
notIn(Z,Visited),
S1 is S+W,
path(Z,Y,[Z|Visited],Cs, S1, P). <-(2)
? path(ori, dest, X, 0, P).
connection(ori,a,2).
connection(a,b,5).
connection(b,a,4).
connection(b,dest,1).
notIn(A, []).
. The variableA
only occurs once, in the head (there is no body). So this has the same meaning asnotIn(_, []).
I'm glad you're taking singleton variable warnings seriously, as they usually indicate logical errors! This particular one is an example of a harmless one, but you should replace it with the_
anyway. – Daniel Lyons[X,P]
flagged as singletons. Is this all of the code and is it the version of code you saw the error for? And what's the significance of the line labeled <- (2)? – lurker