<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 02/18/2013 11:11 AM, Willem van
      Asperen wrote:<br>
    </div>
    <blockquote cite="mid:5121FE52.90301@van.asperen.org" type="cite">
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      Hi All,<br>
      <br>
      Just wanted to share with you an easy mistake. This is done
      running Drools 5.5.0.Final.<br>
      <br>
      Imagine a fact<br>
      <br>
      <code>Cheese (</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; creationTick : double</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; preservationTicks : double</code><code><br>
      </code><code>)</code><br>
      <br>
      Then the following does not do what you expect:<br>
      <br>
      <code>rule "dump old cheese"</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; when</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $c : Cheese( $sbd : creationTick +
        preservationTicks )</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CurrentTime( tick &gt;= $sbd )</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; then</code><code><br>
      </code><code>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("</code><code>we have to
        dump "+$c);</code><code><br>
      </code><code>end</code><br>
      <br>
      You would expect that $c is dumped when current time has passed
      creationTick + preservationTicks. But no. The variable $sbd is
      bound to creationTick <i>before</i> the preservationTicks are
      added!! I must say that I do not quite understand how ($sbd :
      creationTick) + preservationTicks resolves to "true" to make the
      premise succeed... Maybe because it is != 0?<br>
      <br>
      I found that it should be:<br>
      <br>
      <code>rule "dump old cheese"</code><code><br>
      </code><code> &nbsp;&nbsp;&nbsp; when</code><code><br>
      </code><code> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $c : Cheese( $sbd : (creationTick +
        preservationTicks) )</code><code><br>
      </code><code> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CurrentTime( tick &gt;= $sbd )</code><code><br>
      </code><code> &nbsp;&nbsp;&nbsp; then</code><code><br>
      </code><code> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("we have to dump "+$c);</code><code><br>
      </code><code> end</code><br>
      <br>
      This makes sense. Now $sbd is bound to the result of the addition.
      But it is an easy trap!!<br>
      <br>
      Regards,<br>
      Willem<br>
    </blockquote>
    Hi All,<br>
    <br>
    Coming back to this... What will be evaluated in the following
    snippet:<br>
    <br>
    rule "dump old cheese"<br>
    &nbsp;&nbsp;&nbsp; when<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CurrentTime( $tick : tick )<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $c : Cheese( $tick &gt;= creationTick + preservationTicks )<br>
    &nbsp;&nbsp;&nbsp; then<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("we need to dump "+$c);<br>
    end<br>
    <br>
    I assume this evaluates if $tick is larger or equal to (creationTick
    + preservationTicks), right? Otherwise it would say<br>
    <br>
    step 1: &nbsp;&nbsp; $tick &gt; creationTick + preservationTicks<br>
    step 2: &nbsp;&nbsp; true + preservationTicks<br>
    <br>
    which would fail, obviously because you cannot add a double to a
    boolean.<br>
    <br>
    Regards,<br>
    Willem<br>
  </body>
</html>