title: Prolog - Constraint Library - Variable Scope
body: <p>I'm working on trying to solve an LSAT logic problem with Prolog. I'm trying to get Prolog to tell me whether possible values for actors in a line are valid.</p>
  
  <p>I wrote the following:</p>
  
  <pre><code>:- use_module(library(clpfd)).
  
  actor("Jeff",A) :-
          A #&gt;= 0,
          A #&lt;5.
  actor("Rich",C) :-
          C #&gt;= 0,
          C #&lt;5,
          actor("Jeff",A),
          A #&lt; C.
  </code></pre>
  
  <p>When I query:</p>
  
  <pre><code>?- actor("Rich",0).
  false.
  </code></pre>
  
  <p>Which is right since Jeff is &lt; than Rich and Jeff is => 0 so Rich cannot be 0.</p>
  
  <p>But, when I query:</p>
  
  <pre><code>?- actor("Jeff",1), actor("Rich",1).
  true 
  </code></pre>
  
  <p>I also get true, which is impossible because Rich > Jeff. </p>
  
  <p>I feel the problem is because of something going on with my variable. I don't understand how </p>
  
  <pre><code>actor("Jeff",A),
  A #&lt; C.
  </code></pre>
  
  <p>is evaluating. It seems to me that actor("Jeff",A) should be set to actor("Jeff",1) and then 1 #&lt; 1 should fail.</p>