title: Prolog recursively append the list
body: <p>Here's a code which recursively add the element X at the end of the list.</p>
  
  <pre><code>app(X, [], [X]).
  app(X, [Y | S], [Y | S2]) :- app(X, S, S2).
  </code></pre>
  
  <p>Could anyone explain me how it works? Where's the return statement, what exactly the <code>app(X, S, S2)</code> <code>[Y | S], [Y | S2]</code> do?</p>