Subject: I am having trouble writing replace/4

From: "Douglas Miles (Volt Computer)" <[email-masked]>
Date: Thu, 6 Jan 2000 20:18:35 -0800

replaceList([],[],NothingToDo,NothingToDo):-!.
replaceList([HeadBefore|TailBefore],[HeadAfter|TailAfter],Start,End):-!,
        replace(HeadBefore,HeadAfter,Start,Midde),
        replaceList(TailBefore,TailAfter,Middle,End).

replace(_, _, [], []):-!.
replace(A, B, [A|L], [B|R]) :- !,    replace(A, B, L, R).
replace(A, B, [C|L], [C|R]) :-   replace(A, B, L, R).

here is my trouble..

?- replaceList([a,b],[A,B],[1,2,3,a,b,c,x,y,z],O).
A = b
B = _G422
O = [1, 2, 3, _G422, _G422, c, x, y, z]
yes

I guess the real question is how can I write a replace only once..  or
rewrite replaceList?

I want it to do this...

?- replaceList([a,b],[A,B],[1,2,3,a,b,c,x,y,z],O).
A = _G421
B = _G422
O = [1, 2, 3, _G421, _G422, c, x, y, z]
yes

is copy_term/2 the key? I have tried a few tricks..
or maybe numbervars can help?

Any Suggestions?

Thank you, 
	Douglas Miles [email-masked]