title: Prolog: Return list of Y from facts where X = x
body: <p>I'm pretty new to Prolog and can't wrap my head around a certain problem.
  Say I have a couple of Facts <em>fact(X,Y)</em>:<br />
  fact(a, m).<br />
  fact(b, m).<br />
  fact(c, n).<br />
  fact(x, q).<br />
  fact(x, y).<br />
  fact(x, z).</p>
  <p>I would like to create a list of all Y of facts with a specific X.
  For Example:<br />
  ?- getList(x, LIST).<br />
  LIST = [q,y,z].</p>
  <p>q,y,z are returned because they are found in facts where X = x.</p>
  <p>Is there a quick way to do this? I have tried using recursion to iterate through all fact(x, Y) and append each Y but I couldn't make it work.</p>
  <p>Thank you in advance!</p>