[rules-users] DRL Functions

Wolfgang Laun wolfgang.laun at gmail.com
Wed Oct 13 13:45:14 EDT 2010


Implementing this would require a detailed parsing of function bodies and
more,
to get the runtime object into the scope of the static methods compiled from
DRL functions.

As it is, a minor improvement is possible with:

import org.drools.spi.KnowledgeHelper;

function void ins( KnowledgeHelper kh, Object... obj ){
    kh.insert( obj );
}

//...
then
    ins( drools, new Fact( ... ) );
end


2010/10/13 Swindells, Thomas <TSwindells at nds.com>

>  I’ve just been writing what should be a really simple function in my DRL.
>
> What I wanted to do is to take an object in, construct another object from
> it and then insert both into working memory.
>
> Eg.
>
> *function* *void* insertBoth(Object1 object1) {
>
>       insert(new Object2(object1));
>
>       insert(object 1);
>
> }
>
>
>
> Rule XYZ
>
> When
>
> Then
>
>                 insertBoth(new Object1());
>
> End
>
>
>
>
>
> This didn’t work as expected however as it couldn’t find the method insert.
>
> I then thought, ah maybe I need to use the kcontext global to access them
>
>
>
> *function* *void* insertBoth(Object1 object1) {
>
>       kcontext.insert(new Object2(object1));
>
>       kcontext.insert(object 1);
>
> }
>
>
>
> Rule XYZ
>
> When
>
> Then
>
>                 insertBoth(new Object1());
>
> End
>
>
>
> This doesn’t work either so what I’ve had to do is:
>
>
>
> *function* *void* insertBoth(KnowledgeContext kcontext, Object1 object1) {
>
>       kcontext.getKnowledgeRuntime().insert(new Object2(object1));
>
>       kcontext.getKnowledgeRuntime().insert(object 1);
>
> }
>
>
>
> Rule XYZ
>
> When
>
> Then
>
>                 insertBoth(kcontext, new Object1());
>
> End
>
>
>
> This is suddenly a lot more complicated than it needs to be.  Why can’t
> functions have the same access to the standard operations (insert, update,
> retract etc) and globals as rule actions currently do?
>
> Should I raise an issue for this or am I missing something?
>
>
>
> Thomas
>
> ------------------------------
>
>
> **************************************************************************************
> This message is confidential and intended only for the addressee. If you
> have received this message in error, please immediately notify the
> postmaster at nds.com and delete it from your system as well as any copies.
> The content of e-mails as well as traffic data may be monitored by NDS for
> employment and security purposes. To protect the environment please do not
> print this e-mail unless necessary.
>
> NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18
> 4EX, United Kingdom. A company registered in England and Wales. Registered
> no. 3080780. VAT no. GB 603 8808 40-00
>
> **************************************************************************************
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101013/67319306/attachment.html 


More information about the rules-users mailing list