title: Best way to generate integer numbers in Prolog
body: <p>I want to generate integer numbers and I'm looking for the best way to do this. Example:</p>
  
  <pre><code>?- number2(N).
  N = 0;
  N = 1;
  N = 2;
  ...
  (and so on)
  </code></pre>
  
  <p>Now I'm simply using <code>length/2</code>:</p>
  
  <pre><code>number2(N) :- length(_, N).
  </code></pre>
  
  <p>But I think that there should be some better way (without creating temporary list). I could probably write some code myself basing on code of <code>length/2</code> but I'm looking for solution that employs already existing, built-in predicates. Is there any built-in predicate that would work better than <code>length/2</code>? I couldn't find anything like that.</p>