[rules-users] No globals in functions?

Bagwell, Allen F afbagwe at sandia.gov
Mon Oct 13 09:59:10 EDT 2008


Edson,

Thanks for the tip. I figured I'd need to use a workaround like this.

Unfortunately I'm under a series of tight development and test deadlines all the way into early summer. Otherwise, I'd have a look. Hopefully someone else out there can assist.

Thanks,
-A

________________________________
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Friday, October 10, 2008 5:46 AM
To: Rules Users List
Subject: Re: [rules-users] No globals in functions?


   Allen,

   There is a technical explanation behind that and we never had the time to find a way to overcome this limitation. What you can do, although not ideal, is to send the global as a parameter:

funcion void foo( Logger log, String cond )
{
...
}

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

   If you or anyone would like to help improving this, let us know and we can discuss ways into doing it.

   []s
   Edson

2008/10/9 Bagwell, Allen F <afbagwe at sandia.gov<mailto:afbagwe at sandia.gov>>

There's probably an easy explanation for this. I was wondering about why functions inside of rule files can't access globals?

For example, I have a log4j logger that I pass into my rule files via a global.  The logger should never be a part of working memory. It's just there to capture valuable feedback.

But I can't do this:

global Logger log;

function void foo(String cond)
{
   if (cond == "error")
       log.error("I saw an error");
}

Because the compiler says that in the function it can't resolve 'log'.

-A

Allen F. Bagwell
e-mail:  afbagwe at sandia.gov<mailto:afbagwe at sandia.gov>
phone:  505/284-4517
fax:  505/ 844-7886

There is no monument dedicated to the memory of a committee. -- Lester J. Pourciau




_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org<mailto:rules-users at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users




--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com<http://www.jboss.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081013/a119e7f3/attachment.html 


More information about the rules-users mailing list