How can I replace a list with another list that contain the variable to be replaced. for example
rep([x, d, e, z, x, z, p], [x=z, z=x, d=c], R). R = [z, c, e, x,
If you use SWI-Prolog, with module lambda.pl found there : http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/lambda.pl you can write :
:- use_module(library(lambda)). rep(L, Rep, New_L) :- maplist(\X^Y^(member(X=Z, Rep) -> Y = Z ; Y = X), L, New_L).