title: Prolog: replace an element in a list at a specified index
body: <p>I'd like to have a Prolog predicate that can replace an element in a list at a specified index.</p>
  
  <p>Example:</p>
  
  <pre><code>% replace(+List,+Index,+Value,-NewList).
  ?- L=[a,b,c,d], replace(L,1,z,L2).
  L2 = [a,z,c,d]
  </code></pre>
  
  <p>I don't know how to do this. Thanks for your help! Loïc.</p>