Re: Replace occurrence of a list with another?
- From: Bill Spight <bspight@xxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 17:15:43 GMT
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
.
- Follow-Ups:
- Re: Replace occurrence of a list with another?
- From: brianbasquille
- Re: Replace occurrence of a list with another?
- References:
- Replace occurrence of a list with another?
- From: brianbasquille
- Replace occurrence of a list with another?
- Prev by Date: Re: Create a List of Lists
- Next by Date: Re: Replace occurrence of a list with another?
- Previous by thread: Replace occurrence of a list with another?
- Next by thread: Re: Replace occurrence of a list with another?
- Index(es):