Rulz.NET: a proposed rules-based programming language for Mono and .NET.
Rulz.NET is a rules based extension to C#.
It is intended to bring benefits of rules-based programming to a (potentially) much wider audience -
the VB and C# programmers, not just people with academic/Prolog background.
|
Intial release, 2004 Aug |
In this initial release, I ask your help in checking whether the compiler runs on all platforms,
and ask your comments on the language design.
In particular, the suitability of adding reversibility via an attribute - [Reversible].
But also want to hear your thoughts on the new keywords, on market needs, etc.
|
|
|
Why do I need a rules-based language?
You want to use a rules-based language for solving these complex and difficult to maintain problems:
Multiple nested if-else-if conditional tests that are difficult and expensive to maintain
Duplicated code that performs a particular action and its inverse/reverse action
Business logic rules currently held in separate and often disparate modules
A rules-based solution offers the benefit of querying the ruleset.
You can query against the rules in of of the following ways:
The first rule that matches input
All rules that match input
Reverse lookup to generate input parameters for a rule to match
Features
Rulz.NET was designed to offer some features which are missing from other solutions:
1. Compile time safety
2. Use Visual Studio .NET for debugging
3. Interop with .NET languages
4. Run on both Windows and Linux (and anywhere else where Mono can run)
Rules are created directly in C#
rather than an external definition file where you have to learn a whole new syntax.
There are four new keywords for manipulating rules:
rinterface, rclass,
rule and where.
The rclass denotes a rules class, which is a regular CLR class,
with compiler-added methods for querying the ruleset.
Each rclass contains one rinterface, which is public by default.
This rinterface specifies the arguments and return values, common to all rules,
and thus allows the outside world to call into the rule-set.
Finally, an rinterface is followed by multiple rules,
each of whom can match different conditions.
You can match by argument type, by literal value, or by specifying a custom where clause.
Important Admission: Rulz.NET does not yet implement the Rete alogrithm.
What does the language look like?
Here is a simple example - Hypo airline defines a general interface to calculate overtime pay for any employee,
and adds one specific rule for pilots.
public class Employee { }
public class Pilot : Employee { }
public class Steward : Employee { }
public rclass CalculateOvertimePay
{
rinterface int overtimePay(Employee employee, int overtimeHours);
rule int overtimePay(Pilot pilot, int overtimeHours)
where(overtimeHours>40)
{
throw new FAA_Exception();
}
rule int overtimePay(Pilot pilot, int overtimeHours)
{
return 2*overtimeHours;
}
rule int overtimePay(Steward steward, int overtimeHours)
{
return 1*overtimeHours;
}
}
Links to other rules engines for Java and .NET
Name | URL | Platform | Rete? | Features |
Drools | drools.org | Java | Yes | Strong community, looks like XML |
Jess | sandia.gov | Java | Yes | Strong community, looks like Prolog |
P# | dcs.ed.ac.uk | .NET | Yes | Complicated C# bindings |
Mercury | melbourne au | .NET | Yes | To be reviewed |
See also: http://javarules.org