[rules-users] mythical functions

Barry Kaplan groups1 at memelet.com
Sun Dec 20 15:35:24 EST 2009



Chris Richmond wrote:
> 
> So..assuming I *did* want to put a simple function in my .drl
> file..*where*
> do I have to put it?  My oringal question about how to make a simple
> function declaration is still a mystery to me.
> 

Did this ever get answered? I have never been able to use a function. I
always get mvel compile errors.

Consider this:

----
package systeminsights.plugin.core.schedule

dialect "mvel"

function String f() {
  return "function";
}

rule "Invoke function"
when
  eval(true)
then
  System.out.println("*** f=" f())
end
----


With strict mvel:

[Error: Failed to compile: 1 compilation error(s): 
 - (1,3) unable to resolve method using strict-mode: java.lang.Object.f()]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]
	at
org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:78)


With non-strict mvel:

org.drools.runtime.rule.ConsequenceException: rule: Invoke function

	at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:975)
	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:915)
	at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1121)
	at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:698)
	at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:664)
	at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:198)
	at
systeminsights.infra.drools.DroolsGroovyTestFixture.fireAllRules(DroolsGroovyTestFixture.groovy:89)
	at
systeminsights.infra.drools.DroolsGroovyTestFixture._clinit__closure19(DroolsGroovyTestFixture.groovy:226)
	at
systeminsights.infra.drools.DroolsGroovyTestFixture.getProperty(DroolsGroovyTestFixture.groovy)
	at systeminsights.plugin.core.schedule.FunctionsTest.With device(_) ->
device(_) is effective(FunctionsTest.groovy:19)
Caused by: [Error: unable to access property (null parent): f]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]


-- 
View this message in context: http://n3.nabble.com/functions-tp60463p95669.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list