Edson Tirelli was heard to exclaim, On 11/28/06 03:42:
>    Looking at your questions, it feels like you are stretching the 
> meaning of declarative programming, if you know what I mean. :)

What I'm trying to do has little relation to declarative or any other style of
programming.  I'm trying to find a way to avoid repetition, so that the rules
are more maintainable.

>    Maybe if you can show us the real use case (or something close), we 
> can help you figure out a way to do it...

I've got a bunch of date-based rules, each of which has a different threshold,
 the number of days before some event during which the rule applies.  When a
rule fires, a number of points are assigned, based on a count, and a
multiplier.  The multiplier is determined based on how close to the deadline
you are, as a percentage of the threshold.

So, I need to specify the threshold in the LHS, so we know if the rule should
fire at all, and I need to use it in the RHS, to determine the multiplier.

The intent is that users will define rules, including the length of the
threshold.  If they have to enter the number twice, there's a chance that
they'll mistype it in one of the places.  If it's in the rule twice, it's very
likely that someone editing the rule later will only change one of the
occurrences, leaving the rule inconsistent.

Here's a (sanitized) example:

rule "Start worrying a month before"
 when
  UpcomingEvent( $daysUntil : daysUntil < 28 )
  thing : ThingType(set : stuff -> (countStuff(set) > 0))
 then
  thing.scoreBasedOnThreshold(countStuff(set), $daysUntil, 28);
end

The "28" appears twice, and that makes me sad.  I'd like to replace it with a
variable that's declared once and referenced twice.

Right now I'm leaning towards letting users write the LHS, and then generating
the RHS by parsing the threshold out of the LHS.  I'd really rather not go
this route, because it's a bunch of work.

-- 
Dirk Bergstrom               [EMAIL PROTECTED]
_____________________________________________
Juniper Networks Inc.,          Computer Geek
Tel: 408.745.3182           Fax: 408.745.8905

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to