Re: Replace occurrence of a list with another?



Dear Brian,

Need to replace all occurrences of an element in another list with
another? X being the element i wish to replace and Y being the element
to replace it with so when i issue:

?- replaceall(a,b,[a,b,c,d],L).

It should return L = [b, b, c, d] but i get two values back for L;

L = [b, b, c, d] ;
L = [a, b, c, d] ;

It seems to be returning both the new list and the old list.. why is
this? The predicate is below:

replaceall(X,Y,[H|T],[Y|List]) :-
X = H,
replaceall(X,Y,T,List).

replaceall(X,Y,[H|T],[H|List]) :-
replaceall(X,Y,T,List).

What does this clause say?


replaceall(_,_,[],[]).


Best wishes,

Bill
.