title: Prolog Best Practice: checking if a variable is already bound.
body: <p>I posted <a href="https://stackoverflow.com/questions/2984104/prolog-beginner-how-to-make-unique-values-for-each-variable-in-a-predicate/3000352#3000352">this solution</a> to an question but <a href="https://stackoverflow.com/users/230744/ony">ony</a> left me a comment saying:</p>
  
  <blockquote>
    <p>Predicates to check if "variable" is
    free or already bound should change
    strategy for deriving right
    unifications for other "variables"
    (i.e. speed up, or make possible to
    derive them). The same for dynamic
    predicates - they can be used to
    speed-up something, but they shouldn't
    be used as trigger of changing
    behaviour of something.</p>
  </blockquote>
  
  <p>I am wondering why this is.  Why is it bad practice to check if something is already defined to something else?  Do you think it is bad practice?  Are there other options that would be 'better practice'.  </p>
  
  <p>Here was my solution:  </p>
  
  <pre><code>% ================================
  % Ensures that all variables are unique.  
  % ================================
  
  % Base case: Assigned variables unique values
  used([], Nin, Nin).
  
  % Have already assigned a value to this variable
  used([A|B], Nin, Nout) :-
          integer(A), % &lt;----------------- THIS IS THE LINE IN QUESTION
          helper(B,Nin,Nout).
  
  % Have not assigned a value to this variable yet
  % Assign it and remove it from the list.  
  used( [A|B] , Nin, Nout) :-
          member(A,Nin),
          delete(Nin,A,Temp),
          helper(B,Temp,Nout).
  </code></pre>