Variables are declared in the variables {... } section of a ruleset; this section appears immediately after any ruleset processing option statements:
ruleset <nameOfRuleSet> {
<Processing Options Statement>*// Zero or more statements variables { <Variable Declaration Statement>+ // One or more statements } . . . } |
The variables section:
Variable declaration statements:
Boolean variables can have one of two values: either true or false. You must specify an initial value for the variable when you declare it.
Syntax
[static] Boolean <variableName> = new Boolean ( true | false )
Parameters
Example
RuleSet <nameOfRuleSet> ( Variables( Boolean isMale = new Boolean(true); // The initial value of 'isMale' is true // Whenever the ruleset is processed, 'isMale' // is reset to its initial value of true. static Boolean runOnce = new Boolean(false); // The initial value of 'runOnce' is false // This variable is not reset, so it retains // the value it had at the last process cycle. ) . . . ) |
Categorical variables essentially hold string data. However, these variables may not be assigned any arbitrary string; they must be assigned a value from a predefined list of strings that you declare along with the variable. While you can declare numbers in the list of strings, numbers are treated as strings. This means that the numbers "1" and "1.0", for example, are two different strings and they do not compare equally. "ABC" and "abc" are also two different strings that do not compare equally.
You must define at least one string for a categorical variable. The initial value of a categorical variable is "Able_NULL_Able". However, you may not test for this value, or assign this value unless you explicitly declare it in the string list for the variable.
Syntax
[static] Categorical <variableName> = new Categorical ( <strings>+ )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Categorical Color = new Categorical( "black", "green", "green and black", "orange and black" ); Categorical Legs = new Categorical( "6", "8" ); Categorical Shape = new Categorical( "elongated", "round" ); ) . . . ) |
Continuous variables are defined over a domain of continuous numbers.
The keyword "to" is optional or it may be replaced with a comma.
Syntax
[static] Continuous <variableName> = new Continuous (<low> [to | ,] <high> )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Continuous Percent_Complete = new Continuous(0 to 100); Continuous Percent_Complete = new Continuous(0,100); Continuous Percent_Complete = new Continuous(0 100); ) . . . ) |
Discrete variables essentially hold numeric data. However, these variables may not be assigned any arbitrary number; they must be assigned a value from a predefined list of numbers that you declare along with the variable. While you can declare numbers using different syntax, numbers are all stored internally as Java doubles. This means that the numbers 1, 1.0, and +1.000, for example, are all the same number and compare equally.
You must define at least one number for a discrete variable. The initial value of a discrete variable is Double.NaN. However, you may not test for this value, or assign this value, explicitly in a rule.
Syntax
[static] Discrete <variableName> = new Discrete (<numbers>+); )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Discrete Legs = new Discrete( 6, 8 ); Discrete Wings = new Discrete( 0.0, 2.0 ); ) . . . ) |
Fuzzy variables are defined over a domain of continuous numbers. Within this range of numbers, one or more fuzzy sets must be defined; therefore, at least one fuzzy set definition is always required to follow a Fuzzy variable declaration.
The keyword "to" is optional or it may be replaced with a comma.
Syntax
[static] Fuzzy <variableName> = new Fuzzy (<low>,<high>) { <fuzzySetDeclarations>+ ) }
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Fuzzy Percent_Complete = new Fuzzy(0 to 100) { ... } ; Fuzzy Percent_Complete = new Fuzzy(0,100) { ... }; Fuzzy Percent_Complete = new Fuzzy(0 100) { ... }; ) . . . ) |
List variables are special. Being lists, they cannot easily be compared to other variables, but they can be assigned from other variables. A set of List Library functions, which are built-in and always available in a ruleset, can be used to manipulate lists and extract elements from lists. Refer to the documentation for the com.ibm.able.rules.AbleListLib package for complete information. You can also examine the AbleListLibDemo.arl source rule language file in the examples/rules directory for additional insight. List are implemented as Java Vectors.
Syntax
[static] List <variableName> = new List ( <element*> );)
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( List foo = new List(); List bar = new List( ); List baz = new List("abc", 12.34, "56", 7.89, true); List bax = new List(foo, bar, baz); ) . . . ) |
Later on, in a rule block, you might refer to a list variable in this way:
Rules( a1: foo = "foo"; // Result: ["foo"] a2: bar = 67.89; // Result: [67.89] a3: foo = listAdd(foo, "baz"); // Result: ["foo", "baz"] a3: foo = listAddAll(foo,baz); // Result: ["foo", "baz", // "abc", 12.34, "56", 7.89, true] ) |
Numeric variables can be assigned any numeric value; internally, they are represented as doubles.
Syntax
[static] Numeric <variableName> = new Numeric (<initialValue>); )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Numeric NumberOf_Enrollees = new Numeric(50); Numeric PercentComplete = new Numeric(0.34); static Numeric decrementAmount = new Numeric(-5.0); static Numeric incrementAmount = new Numeric(+10); ) . . . ) |
Object variables can be assigned any arbitrary Java object. Object variables cannot be assigned an initial value when they are declared; they have an initial value of null.
Syntax
[static] Object <variableName> = new Object();
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Object Subruleset1 = new Object(); Object something = new Object(); ) . . . ) |
Later on, you might refer to the variables in the following way:
Rules( a1: Subruleset1 = getNewRuleset("foo"); // Assign function value a2: something = 67.89; // Assign a number a3 something = "What's up"; // Assign a string ) |
String variables can be assigned any string value. String comparisons are always case sensitive.
Syntax
[static] String <variableName> = new String (<initialValue>); )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( String Size = new String("Large"); String ErrorMessage = new String("Fatal Error"); ) . . . ) |
User-defined data typed variables are variables whose values are instances of classes specified using import statments. The variables are created and initialized when declared. If the underlying class has public data members, or data members that have public "get" and/or "set" methods, the data members can be referenced in rules by using the variable name followed by a dot, followed by the member name; for example, foo.diameter, where diameter is a member in the variable named foo.
See also the import statement.
Syntax
[static] <userType> <variableName> = new <userType> (<arg>*); )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Puzzle foo = new Puzzle("HardPuzzle"); // CTOR takes name Ring bar = new Ring("RingA", 12.0); // CTOR takes name & diameter ) . . . ) |