Re: [rules-users] Simple Global Error !!

2012-07-16 Thread Wolfgang Laun
On 16/07/2012, Esteban Aliverti  wrote:

> @Abhinay, the truth is that Drools transforms the RHS of a rule is into a
> java class. And, just like Wolfgang says, globals are stored in some kind
> of Map, so you must use setGlobal() if you want to change the value of a
> global in drools.
>

That's exactly what's missing from the Drools Expert manual :)
-W
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Simple Global Error !!

2012-07-16 Thread Wolfgang Laun
On 16/07/2012, Esteban Aliverti  wrote:
> No matter the type of a variable or whether it is inmutable or not, if you
> reassign a variable inside a method you are not going to see that change
> outside the method.

void method(){
   x += 1;
}

If x is a class member, the change remains.

If x is a static class field, the change remains.

> Each method in java receives a copy of the variable
> (pointing to the same object of course) we are passing.

If you are talking about the implementation of consequences in DRL,
this may be so; but it isn't a necessity to be implemented in this
way. In particular, the Expert documentation doesn't raise any "red
flags" along these lines.

-W
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Simple Global Error !!

2012-07-16 Thread abhinay_agarwal
setGlobal() works for me !!...tnxx !! :) :)

--
View this message in context: 
http://drools.46999.n3.nabble.com/Simple-Global-Error-tp4018697p4018703.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Simple Global Error !!

2012-07-16 Thread Wolfgang Laun
It may not be quite so simple as that - using int to illustrate a
problem occuring with Integer is misleading.

An Integer is an immutable object.
   Integer a = Integer.valueOf( 42 );
   a += 1
You'll certainly still have an Integer object available via 'a', but
it's *not* the one containing 42 any more - that's already in the
garbage.

The situation is aggravated by the fact that a 'global' is stored in a
sort of container and this container is not directly accessible for
effecting a change, only via setGlobal().

-W

On 16/07/2012, Esteban Aliverti  wrote:
> Let's say you have this method in a java class:
>
> public void addOne(int number){
>number = number +1;
> }
>
>
> And let's say you want to invoke that method from another method in the
> same (or a different. It doesn't matter) object:
>
> int number = 0;
> this.addOne(number);
> System.out.println("Number= "+number);
>
> What is the output of the code above? Figure out that and you will figure
> out what is happening with your global.
>
> Best Regards,
>
> 
>
> Esteban Aliverti
> - Blog @ http://ilesteban.wordpress.com
>
>
> On Mon, Jul 16, 2012 at 11:53 AM, abhinay_agarwal <
> abhinay_agar...@infosys.com> wrote:
>
>> global java.lang.Integer count
>>
>>
>> rule "rule1"
>> agenda-group "1"
>> when
>>//smething
>> then
>>   count=0;
>>   System.out.println(count); // output is 0
>>   count = count +1;
>>   System.out.println(count); // output is 1
>>   drools.setFocus("2");
>> end
>>
>>
>> rule "rule2"
>> agenda-group "2"
>> when
>>//smething
>> then
>>   System.out.println(count); // output is 0
>> end
>>
>> in the rule2, the value of the global variable "count" must be 1, why m i
>> getting it as zero ?
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/Simple-Global-Error-tp4018697.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Simple Global Error !!

2012-07-16 Thread abhinay_agarwal
hey,

i know that the "number" is local to the function so it wont show the
incremented value, when the function is called...

but i ve declared the global n m not redeclaring it in the rules !

regards,
Abhinay

--
View this message in context: 
http://drools.46999.n3.nabble.com/Simple-Global-Error-tp4018697p4018699.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users