title: How to add to end of list in prolog
body: <p>I am trying to add one item to the end of a list in prolog, but it keeps on failing. </p>
  
  <pre><code>insertAtEnd(X,[ ],[X]).
  insertAtEnd(X,[H|T],[H|Z]) :- insertAtEnd(X,T,Z).    
  
  letters([a,b,c]).
  </code></pre>
  
  <p>I do not understand why this below does not work.</p>
  
  <pre><code>insertAtEnd(d,letters(Stored),letters(Stored)). 
  </code></pre>
  
  <p>I am also attempting to store this list in the variable Stored throughout, but I am not sure if the above is correct way to proceed.</p>