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
<variableName> [static] Boolean ( True | False )
Parameters
Example
RuleSet <nameOfRuleSet> ( Variables( isMale Boolean(True) // The initial value of 'isMale' is true // Whenever the ruleset is processed, 'isMale' // is reset to its initial value of true. runOnce static 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
<variableName> [static] Categorical ( <strings>+ )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Color Categorical( "black", "green", "green and black", "orange and black" ) Legs Categorical( "6", "8" ) Shape 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
<variableName> [static] Continuous (<low> [to | ,] <high> )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Percent_Complete Continuous(0 to 100) Percent_Complete Continuous(0,100) Percent_Complete 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
<variableName> [static] Discrete ( <numbers>+ )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Legs Discrete( 6, 8 ) Wings 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, the SetDefinitions(...) statement with 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
<variableName> [static] Fuzzy (<low> [to | ,] <high> ) SetDefinitions( <fuzzySetDeclarations>+ )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Percent_Complete Fuzzy(0 to 100) SetDefinitions( ... ) Percent_Complete Fuzzy(0,100) SetDefinitions( ... ) Percent_Complete Fuzzy(0 100) SetDefinitions( ... ) ) . . . ) |
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 rsListVariables.rs source rule language file in the examples/rules directory for additional insight.
Syntax
<variableName> [static] List ( <element*> )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( foo List() bar List( ) baz List( "abc", 12.34, "56", 7.89, true ) bax 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
<variableName> [static] Numeric ( <initialValue> )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( NumberOf_Enrollees Numeric(50) PercentComplete Numeric( 0.34 ) decrementAmount static Numeric(-5.0) incrementAmount static 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
<variableName> [static] Object ()
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Subruleset1 Object() something 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
<variableName> [static] String ( <initialValue> )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( Size String("Large") ErrorMessage String( "Fatal Error" ) ) . . . ) |
User-defined data typed variables are variables whose values are instances of specified classes. 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 UserTypes statement.
Syntax
<variableName> [static] <userType> ( <arg>* )
Parameters
Examples
RuleSet <nameOfRuleSet> ( Variables( foo Puzzle("HardPuzzle") // CTOR takes name bar Ring("RingA", 12.0) // CTOR takes name & diameter ) . . . ) |