I have a problem with an exercise of prolog , which is to construct a predicate that given an atom a
as the first argument, a second atom s
as the second argument, is unified to a third parameter L
, which contains a set of numbers corresponding to the positions where the atom a
appears in atom s
. considering 0 as the first position.
As an example I have this:
buscaInstanciasAtom(asa, aSaasasasa, L)
should result in L = [3,5,7]
.
With this in mind, I did the following:
buscaInstanciasAtom(A, S, L):- sub_string(S,Posicion,_,_,A), L=Posicion.
But instead of being L=[3,5,7]
, it results in L=3,L=5,L=7
, and I do not know how to insert in a single list, help please.