title: Replace elements of a list in Prolog
body: <p>I have a predicate <code>variablize/3</code> that takes a list and replaces each item, in turn, with a variable, example:</p>
  
  <pre>
  % ?- variablize([a,b,c], X, L).
  % L = [[X, b, c], [a, X, c], [a, b, X]]
  </pre>
  
  <p>Now I am trying to extend this predicate to accept a list of variables, example:</p>
  
  <pre>
  % ?- variablize([a,b,c], [X,Y], L).
  % L = [[X, Y, c], [X, b, Y], [a, X, Y]]
  </pre>
  
  <p>My code so far is:</p>
  
  <pre>
  replace_at([_|Tail], X, 1, [X|Tail]).
  replace_at([Head|Tail], X, N, [Head|R]) :- M is N - 1, replace_at(Tail, X, M, R).
  
  replace_each([], _, _, [], _).
  replace_each([_|Next], Orig, X, [Res|L], N) :-
      replace_at(Orig, X, N, Res),
      M is N + 1,
      replace_each(Next, Orig, X, L, M).
  
  variablize(I, X, L) :- replace_each(I, I, X, L, 1).
  </pre>
  
  <p>Any pointers? Do I extend <code>replace_at/4</code> to have a list of indexes that should be skipped?</p>