<div dir="ltr"><div>Mark,</div>
<div>&nbsp;</div>
<div>I would be willing to make the changes, but do you think there are bigger fish to fry? </div>
<div>&nbsp;</div>
<div>dave<br><br></div>
<div class="gmail_quote">On Wed, Oct 15, 2008 at 4:49 PM, Mark Proctor <span dir="ltr">&lt;<a href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div text="#000000" bgcolor="#ffffff">The globals are global to the consequence, where we inject them for the user. For the function we expect the user to pass those injected globals as arguments, i&#39;m not convinced that this is overly more painful that the variables automatigically being there in the function.<br>
<br>That said if someone was will doing to do the work, we woudl probably accept the patch. But it would need to do the following.<br>1) determine the used globals for the function<br>2) add those parameters onto the end of the generated function.<br>
3) update any generated consequences, or functions for that matter, and add in the globals to the paramters list.<br><br>So basically a lot of data munging in the templates.<br><br>Mark<br>Greg Barton wrote: 
<blockquote type="cite"><pre>How about a ThreadLocal?

--- On Wed, 10/15/08, David Sinclair <a href="mailto:dsinclair@chariotsolutions.com" target="_blank">&lt;dsinclair@chariotsolutions.com&gt;</a> wrote:

  </pre>
<blockquote type="cite"><pre>From: David Sinclair <a href="mailto:dsinclair@chariotsolutions.com" target="_blank">&lt;dsinclair@chariotsolutions.com&gt;</a>
Subject: [rules-dev] Re: [rules-users] No globals in functions?
To: &quot;Edson Tirelli&quot; <a href="mailto:tirelli@post.com" target="_blank">&lt;tirelli@post.com&gt;</a>
Cc: &quot;Mark Proctor&quot; <a href="mailto:mproctor@codehaus.org" target="_blank">&lt;mproctor@codehaus.org&gt;</a>, &quot;Rules Dev List&quot; <a href="mailto:rules-dev@lists.jboss.org" target="_blank">&lt;rules-dev@lists.jboss.org&gt;</a>
Date: Wednesday, October 15, 2008, 12:53 PM
What about injecting the globals into the classes and doing
reflection to
invoke the method dynamically? That way we would only need
to change the
JavaFunctionBuilder to rewrite the calls to the globals?
For example

function foo() {
    global.bar(abx);
}

gets re-written as

function foo() {
     method.invoke(global, [abx]);
}

methods would be cached and such. Or do you guys not want
the reflection in
there?


On Wed, Oct 15, 2008 at 1:45 PM, Edson Tirelli
<a href="mailto:tirelli@post.com" target="_blank">&lt;tirelli@post.com&gt;</a> wrote:

    </pre>
<div class="Ih2E3d">
<blockquote type="cite"><pre>   It may be invoked by a consequence, an eval, a
      </pre></blockquote><pre>predicate, or a return
    </pre>
<blockquote type="cite"><pre>value constraint.

   If you fix it for the consequence in
      </pre></blockquote><pre>JavaConsequenceBuilder, the others
    </pre>
<blockquote type="cite"><pre>will work the same. You will have to change the java.g
      </pre></blockquote><pre>grammar as I
    </pre></div>
<blockquote type="cite"><pre>mentioned in my previousre e-mail to make it work.

   []s
   Edson

2008/10/14 David Sinclair
      </pre></blockquote>
<div>
<div></div>
<div class="Wj3C7c"><pre><a href="mailto:dsinclair@chariotsolutions.com" target="_blank">&lt;dsinclair@chariotsolutions.com&gt;</a>
    </pre>
<blockquote type="cite"><pre> Edson,
      </pre>
<blockquote type="cite"><pre>Changing the builder shouldn&#39;t be too much of
        </pre></blockquote></blockquote><pre>a problem. If I make the
    </pre>
<blockquote type="cite">
<blockquote type="cite"><pre>changes you suggested, how does the global
        </pre></blockquote></blockquote><pre>actually get passed to the
    </pre>
<blockquote type="cite">
<blockquote type="cite"><pre>method? For example if something defined a
        </pre></blockquote></blockquote><pre>function like
    </pre>
<blockquote type="cite">
<blockquote type="cite"><pre>void function doX(int abc) {
   ...
   global.doY(bcd);
}
and I rewrite it to be

void function doX(int abc, GlobalType global) {
   ...
}

Who is the invoker of the method?

thanks

dave



 On Mon, Oct 13, 2008 at 3:24 PM, Edson Tirelli
        </pre></blockquote></blockquote><pre><a href="mailto:tirelli@post.com" target="_blank">&lt;tirelli@post.com&gt;</a> wrote:
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>   Hi Dave,

   Excellent!
   I will try to explain the current situation
          </pre></blockquote></blockquote></blockquote><pre>and one possible solution,
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>but you may have better ideas.

   Functions in Drools are compiled as simple
          </pre></blockquote></blockquote></blockquote><pre>static methods in a
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>generated java class. We use MVEL Templates to
          </pre></blockquote></blockquote></blockquote><pre>generate the code of the
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>class and the static method.

   Take a look at JavaFunctionBuilder.java
          </pre></blockquote></blockquote></blockquote><pre>class for the code generation
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>call and at javaFunction.mvel for the code
          </pre></blockquote></blockquote></blockquote><pre>template.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>   Now, the problem with globals is that they
          </pre></blockquote></blockquote></blockquote><pre>are scoped to sessions, not
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>rulebases, so you can not resolve them until
          </pre></blockquote></blockquote></blockquote><pre>runtime. You can not for
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>instance, make them a static reference of the
          </pre></blockquote></blockquote></blockquote><pre>generated class and set it at
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>rulebase compilation time.

   So, my suggestion would be to:

1. at compile time, use
          </pre></blockquote></blockquote></blockquote><pre>JavaDialect.analyzeBlock() method to analyze and
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>find out what are the globals that are used by
          </pre></blockquote></blockquote></blockquote><pre>the funcion method code.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>2. modify the code generation to add
          </pre></blockquote></blockquote></blockquote><pre>parameters to that in the method
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>call. So, if &quot;log&quot; is a global and
          </pre></blockquote></blockquote></blockquote><pre>if the function is declared like this:
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>function void someFunction( String param ) {
    // ... code ...
    log.something(...);
    // ... code ...
}

   you detect the use of &quot;log&quot; and
          </pre></blockquote></blockquote></blockquote><pre>add it as a parameter of the generated
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>method:

...
public static void someFunction( Logger log,
          </pre></blockquote></blockquote></blockquote><pre>String Param ) {
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>   ...
}
...

   This way, at runtime we can inject the
          </pre></blockquote></blockquote></blockquote><pre>parameter into the call. You
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>can look at JavaConsequenceBuilder.java and
          </pre></blockquote></blockquote></blockquote><pre>javaInvokers.mvel to see how we
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>do kind-of the same thing for consequences.

3. Now the most interesting part. :)  We use
          </pre></blockquote></blockquote></blockquote><pre>an ANTLR grammar for parsing
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>Java code blocks. You need to change the
          </pre></blockquote></blockquote></blockquote><pre>parser to rewrite any function call
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>the user is doing in his code to inject the
          </pre></blockquote></blockquote></blockquote><pre>log parameter transparently. I
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>did the very same thing for modify blocks:

modify( $something ) {
   ...
}

   It is not hard once you get the hang of it.
          </pre></blockquote></blockquote></blockquote><pre>It is a bit of &quot;hand work&quot;
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>though. Look at the
          </pre></blockquote></blockquote></blockquote><pre>JavaConsequenceBuilder.fixModifyBlocks() for what I did.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>Also, the ANTLR Java grammar is java.g.

   Let me know if you have questions or if you
          </pre></blockquote></blockquote></blockquote><pre>have a better idea, and
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>welcome aboard!

   Cheers,
       Edson



2008/10/13 David Sinclair
          </pre></blockquote></blockquote></blockquote><pre><a href="mailto:dsinclair@chariotsolutions.com" target="_blank">&lt;dsinclair@chariotsolutions.com&gt;</a>
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre> Hi Edson,
          </pre>
<blockquote type="cite"><pre>My name is dave sinclair. I started using
            </pre></blockquote></blockquote></blockquote></blockquote><pre>Drools in early August of this
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>year, but have a lot of experience with
            </pre></blockquote></blockquote></blockquote></blockquote><pre>rules engines. I have worked
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>primarily with ArtEntrprise and some with
            </pre></blockquote></blockquote></blockquote></blockquote><pre>PegaRules. I would love to help
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>with this project and thought that this
            </pre></blockquote></blockquote></blockquote></blockquote><pre>may be the area to jump in on.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>I have the M2 code, and was reading it
            </pre></blockquote></blockquote></blockquote></blockquote><pre>over the weekend. Mostly the core
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>and some of the compilier. If you want to
            </pre></blockquote></blockquote></blockquote></blockquote><pre>point me in the right direction on
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>the global/functions I&#39;d be happy to
            </pre></blockquote></blockquote></blockquote></blockquote><pre>have a look.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>thanks

dave


On Mon, Oct 13, 2008 at 9:59 AM, Bagwell,
            </pre></blockquote></blockquote></blockquote></blockquote><pre>Allen F <a href="mailto:afbagwe@sandia.gov" target="_blank">&lt;afbagwe@sandia.gov&gt;</a>wrote:
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre> Edson,

Thanks for the tip. I figured I&#39;d
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>need to use a workaround like this.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>Unfortunately I&#39;m under a series
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>of tight development and test
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>deadlines all the way into early
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>summer. Otherwise, I&#39;d have a look.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>Hopefully someone else out there can
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>assist.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>Thanks,
-A

 ------------------------------
*From:*
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre><a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre><a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>]
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>*On Behalf Of *Edson Tirelli
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>*Sent:* Friday, October 10, 2008 5:46
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>AM
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>*To:* Rules Users List
*Subject:* Re: [rules-users] No
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>globals in functions?
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>   Allen,

   There is a technical explanation
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>behind that and we never had the
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>time to find a way to overcome this
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>limitation. What you can do, although
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>not ideal, is to send the global as a
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>parameter:
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>funcion void foo( Logger log, String
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>cond )
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>{
...
}

rule XYZ
when
then
    foo( log, someString );
end

   If you or anyone would like to help
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>improving this, let us know and
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>we can discuss ways into doing it.

   []s
   Edson

2008/10/9 Bagwell, Allen F
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre><a href="mailto:afbagwe@sandia.gov" target="_blank">&lt;afbagwe@sandia.gov&gt;</a>
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>There&#39;s probably an easy
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>explanation for this. I was wondering about
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>why functions inside of rule files
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>can&#39;t access globals?
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>For example, I have a log4j logger
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>that I pass into my rule files via
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>a global.  The logger should never
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>be a part of working memory. It&#39;s just
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>there to capture valuable
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>feedback.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>But I can&#39;t do this:

global Logger log;

function void foo(String cond)
{
   if (cond == &quot;error&quot;)
       log.error(&quot;I saw an
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>error&quot;);
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>}

Because the compiler says that in
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>the function it can&#39;t resolve &#39;log&#39;.
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>-A

Allen F. Bagwell
e-mail:  <a href="mailto:afbagwe@sandia.gov" target="_blank">afbagwe@sandia.gov</a>
phone:  505/284-4517
fax:  505/ 844-7886

There is no monument dedicated to
                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>the memory of a committee. -- Lester
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>J. Pourciau





                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre>_______________________________________________
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>

                </pre></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><pre><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>                </pre></blockquote><pre>--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @
              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre><a href="http://www.jboss.com/" target="_blank">www.jboss.com</a>
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre>_______________________________________________
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>

              </pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
    </pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><pre>              </pre></blockquote></blockquote><pre>--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a>

          </pre></blockquote><pre>        </pre></blockquote><pre>--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a>

      </pre></blockquote><pre>_______________________________________________
rules-dev mailing list
<a href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
    </pre></div></div></blockquote><pre>      

  </pre></blockquote><br></div><br>_______________________________________________<br>rules-dev mailing list<br><a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
<br></blockquote></div><br></div>