As an alternative, consider asserting a single Fact Shelf with field x initially 0. Then you could do<br><br>rule &quot;Another box on the shelf&quot;<br>when<br>    b: Box( x == -1, $size : size )<br>    s: Shelf( $x : x )<br>
then<br>    b.setX( $x ); update( b );<br>    s.setX( $x + $size ); update( s );<br>end<br><br>-W<br><br><br><div class="gmail_quote">2009/8/8 Greg Barton <span dir="ltr">&lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">You answer your own question.  Use accumulate:<br>
<br>
rule &quot;Hello World&quot;<br>
<div class="im">        when<br>
                b : Box( x == -1 )<br>
</div>                newX : Integer() from accumulate( box: Box( x != -1 ),<br>
                                  init( int i = 0; ),<br>
                                  action( i += box.size; ),<br>
                                  reverse( i -= box.size; ),<br>
                                  result( i ) )<br>
        then<br>
                System.out.println(&quot;Sum: &quot; + newX);<br>
                b.setX(newX);<br>
                System.out.println(b);<br>
                update(b);<br>
end<br>
<br>
See attached project.<br>
<br>
--- On Sat, 8/8/09, sonia &lt;<a href="mailto:robotnic%2Bdrools@gmail.com">robotnic+drools@gmail.com</a>&gt; wrote:<br>
<br>
&gt; From: sonia &lt;<a href="mailto:robotnic%2Bdrools@gmail.com">robotnic+drools@gmail.com</a>&gt;<br>
&gt; Subject: Re: [rules-users] Strategy for initializing objects<br>
&gt; To: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>
&gt; Date: Saturday, August 8, 2009, 2:36 AM<br>
<div><div></div><div class="h5">&gt; In general: I want to set a property<br>
&gt; in the Box objects, depending on<br>
&gt; all previously set objects..<br>
&gt;<br>
&gt; My goal is to place the boxes one after another, for this I<br>
&gt; keep a<br>
&gt; variable in Box object.<br>
&gt; It seems like the easiest way to accumulate the sizes of<br>
&gt; boxes that<br>
&gt; are already placed.<br>
&gt;<br>
&gt; In the &#39;then&#39; clause, I set the box location, and update<br>
&gt; the X by<br>
&gt; adding the size of the currently placed box.<br>
&gt;<br>
&gt; 2009/8/8 Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;:<br>
&gt; &gt; Your goal and the presented code aren&#39;t clear to me.<br>
&gt; The consequence (after<br>
&gt; &gt; then) contains calls to static/class methods<br>
&gt; (Box.setX()) which isn&#39;t going<br>
&gt; &gt; to change anything in your fact object. The call<br>
&gt; b.setX() might change your<br>
&gt; &gt; object, but this depends on what the class method<br>
&gt; Box.getX() returns.<br>
&gt; &gt;<br>
&gt; &gt; Assuming Drools 5, a typical consequence would look<br>
&gt; like<br>
&gt; &gt;    b: Box(...)<br>
&gt; &gt; then<br>
&gt; &gt;    modify( b ){<br>
&gt; &gt;       setX( ... )<br>
&gt; &gt;    }<br>
&gt; &gt; end<br>
&gt; &gt;<br>
&gt; &gt; -W<br>
&gt; &gt;<br>
&gt; &gt; On Sat, Aug 8, 2009 at 1:48 AM, sonia &lt;<a href="mailto:robotnic%2Bdrools@gmail.com">robotnic+drools@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Hello<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; I want to achieve this:<br>
&gt; &gt;&gt; box1.setX(0)<br>
&gt; &gt;&gt; box2.setX(box1.size());<br>
&gt; &gt;&gt; box2.setX(box1.size + box2.size)<br>
&gt; &gt;&gt; ...<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; I want to do it with rules, and would like to know<br>
&gt; what&#39;s the best<br>
&gt; &gt;&gt; method of initializing (or any other operation<br>
&gt; with varying data) a<br>
&gt; &gt;&gt; group of objects<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; rule &quot;init box&quot;<br>
&gt; &gt;&gt;  when<br>
&gt; &gt;&gt;   b : Box( x == -1)<br>
&gt; &gt;&gt;  then<br>
&gt; &gt;&gt;   b.setX(Box.getX());<br>
&gt; &gt;&gt;   Box.setX( Box.getX() + b.size);<br>
&gt; &gt;&gt; end<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; This does not work.<br>
&gt; &gt;&gt; A single box object is matched several times<br>
&gt; instead of different box<br>
&gt; &gt;&gt; objects.<br>
&gt; &gt;&gt; What is happening? how come a single box object is<br>
&gt; matched several<br>
&gt; &gt;&gt; times? Why doesnt drools choose other instances of<br>
&gt; box?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; What do I need to do to initialize all boxes, once<br>
&gt; for every box?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Thank you.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; --<br>
&gt; &gt;&gt; robosonia<br>
&gt; &gt;&gt; _______________________________________________<br>
&gt; &gt;&gt; rules-users mailing list<br>
&gt; &gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; rules-users mailing list<br>
&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; robosonia<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
<br>
<br>
      </div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>