[rules-users] performing math function in drools

Wolfgang Laun wolfgang.laun at gmail.com
Mon Oct 4 02:15:27 EDT 2010


// appl.transport.Transport.java:
public class Transport {
  public static double tax( double a, int n ){
    return Math.pow( a, (double)n );
  }
}

// transport.drl --------------------------------------------------
import function appl.transport.Transport.tax;
import function java.lang.Math.pow;

dialect "java"

function double sqr( double a ){
  return Math.pow( a, 2.0 );
}

rule "demo"
when
    Cargo( name == "Crate", , limit < ( tax( 20.0, 2 ) ) )
then
    System.out.println( "tax=" + tax( 20.0, 2 )  );
    System.out.println( "pow=" + pow( 20.0, 2.0 )  );
    System.out.println( "sqr=" + sqr( 20.0 )  );
end

-W

2010/10/4 Kripa Nathwani <Kripa.Nathwani at lntinfotech.com>

>  But for using Math.pow() I have to import java.lang in that function.
>
> Even after importing java.lang, it is not recognizing the function add
> giving me error as :
>
> Prohibited package name:java.class
>
>
>
> If you can just forward me the link for that document you mentioned below,
> I can get some useful insight into it.
>
>
>
>
>
> Best Regards,
>
> Kripa
>
>
>
>
>
>
>
> *From:* rules-users-bounces at lists.jboss.org [mailto:
> rules-users-bounces at lists.jboss.org] *On Behalf Of *Leandro Romero
> *Sent:* Monday, October 04, 2010 10:22 AM
> *To:* Rules Users List
> *Subject:* Re: [rules-users] performing math function in drools
>
>
>
> If you want to make a function call in LHS you have to use Eval, it allows
> you to execute any Java code. In this especific case, you can call
> Math.pow() inside of it.
>
> Before using it, I strongly recommend you to read the documentation about
> it.
>
> ______________________________________________________________________
>
> ------------------------------
> This Email may contain confidential or privileged information for the
> intended recipient (s) If you are not the intended recipient, please do not
> use or disseminate the information, notify the sender and delete it from
> your system.
>
> ______________________________________________________________________
>
> _______________________________________________
> 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/20101004/aa44f140/attachment.html 


More information about the rules-users mailing list