[rules-dev] accumulate to acc

Mark Proctor mproctor at codehaus.org
Fri Aug 19 18:55:37 EDT 2011


On 19/08/2011 10:32, Ansgar Konermann wrote:
> Am 18.08.2011 18:38, schrieb Mark Proctor:
>> We are looking to tighten up accumulate, using a new keyword to
>> differentiate. It will use ; for separation, to follow a similar form to
>> a 'for' loop.
>>
>> acc( CE*;
>> <func>*;
>> <guard>? )
>>
> Hi Mark,
>
> from the above description, I don't grok the meaning of the "new acc".
> Could you describe in a few words what "acc" is going to do?
>
> > From a user perspective, I find it hard to differentiate between "acc"
> and "accumulate". I bet this is going to be an eternal source of
> confusion and "which acc is for which purpose?" questions.
>
> If "acc" is different from "accumulate", then I'd like to learn what
> "acc" actually does, how it differs from "accumulate" and try to find a
> keyword which precisely resembles what it does.
The behaviour is the same, it's just more compact and provides a clause 
for a guard, I also want to explore function chaining, like with 
functional programming. I felt we made some mistakes on the accumulate 
syntax and this is an opportunity to try and get it right, without 
breaking backwards compability. The comma separation in the syntax makes 
it very hard to evolve, hence the; in the new 'acc' for the segments. 
further 'accumulate' is quite verbose. I also considered using 'for' 
instead of 'acc', as in essence it is a for loop over a stream of data, 
as I thought maybe developers might find that more familiar.
acc( $o : Order() from list;
         $min : min( $o.value ),
         $max : max( $o.value );
         $min > 100 && $max < 200 );

The above will take a list of Orders and for each value execute the 
function(s) on it. That is the same as if it was an accumulate. We allow 
the function result to be bound, $min and $max are bound to the result. 
We then allow a guard on the result of the accumulate which will only 
allow those results to propagate if the guard is true. Example with 
'for' instead:
for( $o : Order() from list;
         $min : min( $o.value ),
         $max : max( $o.value );
         $min > 100 && $max < 200 );

You could do this on the old accumulate as follows:
$m : Map() from accumulate( $o : Order() from list,
                                                      minMaxFunction( $o 
) ) // user plugged in function that executes two functions and binds 
results to a map.
$min : Number() from $m.min
$max : Number() from $m.max
eval( $min > 100 && $max < 200  )

This is virgin territory, and we need to be free to make mistakes and 
evolve the syntax, while trying to keep backwards compatability as long 
as possible. At some point we can deprecate older syntaxes and produce 
something much cleaner.

Mark
>
> Best regards
>
> Ansgar
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>
>




More information about the rules-dev mailing list