<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16608" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial 
color=#0000ff size=2>The MVEL trick works.&nbsp; That was exactly what I was 
hoping to find.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial 
color=#0000ff size=2>thanks,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial 
color=#0000ff size=2>-Jess</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org 
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Edson 
Tirelli<BR><B>Sent:</B> Tuesday, November 11, 2008 3:40 PM<BR><B>To:</B> Rules 
Users List<BR><B>Subject:</B> Re: [rules-users] top n - accumulate function 
parameters<BR></FONT><BR></DIV>
<DIV></DIV><BR>&nbsp;&nbsp; Accumulate functions support only a single 
parameter, as they are defined now, but would be great if someone can come up 
with a good way of adding support to variable number of 
parameters.<BR><BR>&nbsp;&nbsp; Having said that, you can probably try a quick 
trick for your rules. The way accumulate function works now is that it takes an 
expression as the parameter, evaluate the expression and sends the result of the 
expression to the accumulate function implementation. Example:<BR><BR>... 
accumulate( Cheese( $price: price 
),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sum( $price * 10 ) )<BR><BR>&nbsp;&nbsp; So the engine will calculate $price * 
10 and will send the result into the function implementation.<BR>&nbsp;&nbsp; 
So, if you are using MVEL dialect, you can use the list creation simplified 
syntax to pass multiple parameters to the function. I never tried, but should 
work:<BR><BR>rule xyz<BR>&nbsp;&nbsp;&nbsp; dialect 
"mvel"<BR>when<BR>&nbsp;&nbsp;&nbsp; ...<BR>... accumlate( Cheese( $price : 
price 
),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
averageTop( [10, $price ] ) )<BR>then<BR>&nbsp; 
...<BR>end<BR><BR>&nbsp;&nbsp;&nbsp; The syntax [ ] will create a list in MVEL 
and will pass it into the method call:<BR><BR>&nbsp;&nbsp;&nbsp; public void 
accumulate(Serializable context, Object value) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List values = (List) 
value;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
...<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; Problem is you 
only have the parameters available in the accumulate() and reverse() call... you 
don't have access to them in the init() and result() call.<BR><BR>&nbsp;&nbsp; 
&nbsp; If you want to improve this, you are more than 
welcome!<BR><BR>&nbsp;&nbsp;&nbsp; []s<BR>&nbsp;&nbsp;&nbsp; 
Edson<BR><BR>&nbsp;<BR><BR>
<DIV class=gmail_quote>2008/11/11 Evans, Jess <SPAN dir=ltr>&lt;<A 
href="mailto:JEvans@collegeboard.org">JEvans@collegeboard.org</A>&gt;</SPAN><BR>
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
  <DIV>
  <DIV><SPAN><FONT face=Arial size=2>I'm trying to average top N items.&nbsp; I 
  can of course collect the items and do the rest in the consequence, but 
  thought it might be a scenario applicable to a custom accumulate 
  function.&nbsp; However, the accumulate function interface&nbsp;methods only 
  take one parameter.&nbsp; If I were to declare a function&nbsp;top(N, things) 
  within an accumulate call would drools autobox the parameters into some sort 
  of collection?&nbsp; </FONT></SPAN></DIV>
  <DIV><SPAN><FONT face=Arial size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN><FONT face=Arial size=2>Maybe this is a naive solution 
  anyway.&nbsp; I am still learning to think declaratively.</FONT></SPAN></DIV>
  <DIV><SPAN><FONT face=Arial size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN><FONT face=Arial size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN><FONT face=Arial size=2>cheers,</FONT></SPAN></DIV>
  <DIV><SPAN><FONT face=Arial size=2></FONT></SPAN>&nbsp;</DIV><FONT 
  color=#888888>
  <DIV><SPAN><FONT face=Arial 
  size=2>-Jess</FONT></SPAN></DIV></FONT></DIV><BR>_______________________________________________<BR>rules-users 
  mailing list<BR><A 
  href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A 
  href="https://lists.jboss.org/mailman/listinfo/rules-users" 
  target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR></BLOCKQUOTE></DIV><BR><BR 
clear=all><BR>-- <BR>&nbsp;Edson Tirelli<BR>&nbsp;JBoss Drools Core 
Development<BR>&nbsp;JBoss, a division of Red Hat @ <A 
href="http://www.jboss.com">www.jboss.com</A><BR></BODY></HTML>