LordHelmet666
Programmer
Can someone help me with this?
I have a predicate that returns to me the number of times
the Subterm occurs, but I need it to return to me a list of
the positions it occurs at.
*******************WHAT I HAVE*******************
position(_,[],0).
position(X,[X|L],N) :- position(X,L,M), N is M+1.
position(X,[Y|L],N) :- not(X=Y), position(X,L,N).
*************************************************
?-position(a, [a,b,c,a,d,a,e,a,f], P).
P=4
*************************************************
=================WHAT I NEED=====================
CODE FOR THE FUNCTION TO RETURN LIST OF POSITIONS
=================================================
?-position(a, [a,b,c,a,d,a,e,a,f], P).
%Need the code for this version
%This is what it is supposed to return.
P = [1,4,6,8]
=================================================
Any help would be extremely appreciated.
Thanks
-LordHelmet666
I have a predicate that returns to me the number of times
the Subterm occurs, but I need it to return to me a list of
the positions it occurs at.
*******************WHAT I HAVE*******************
position(_,[],0).
position(X,[X|L],N) :- position(X,L,M), N is M+1.
position(X,[Y|L],N) :- not(X=Y), position(X,L,N).
*************************************************
?-position(a, [a,b,c,a,d,a,e,a,f], P).
P=4
*************************************************
=================WHAT I NEED=====================
CODE FOR THE FUNCTION TO RETURN LIST OF POSITIONS
=================================================
?-position(a, [a,b,c,a,d,a,e,a,f], P).
%Need the code for this version
%This is what it is supposed to return.
P = [1,4,6,8]
=================================================
Any help would be extremely appreciated.
Thanks
-LordHelmet666