0
votes

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).
1
I have some mistakes in the code, is not perfect, just want to understand the warning and how to solve itJulio CMC
I feel I'm using all of themJulio CMC
Consider notIn(A, []).. The variable A only occurs once, in the head (there is no body). So this has the same meaning as notIn(_, []). 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
You're a genius! appreciate your humbleness! @DanielLyonsJulio CMC
I don't see where you'd have [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

1 Answers

0
votes

Singleton variables are ones that are not being used so can be replaced with _.

notIn(A,[]).

Here the variable A is not being used at all so should it should instead be.

notIn(_,[]).

Same thing with the other one. The X and P are not being used so can just go with _ instead.