<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-cite-prefix">Op 18-02-13 14:00, Willem van Asperen
      schreef:<br>
    </div>
    <blockquote cite="mid:512225DC.10205@van.asperen.org" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      <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?</blockquote>
    I think so too.<br>
    It looks like the : operator has a higher precedence then + (and
    therefor &gt;= too), which is a bit surprising indeed.<br>
    Personally, I never mix the : operator with other operators, to
    avoid having to worry about the precendence.<br>
    <blockquote cite="mid:512225DC.10205@van.asperen.org" type="cite">
      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>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>