ARL Master Index


Variable Declaration Statements

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

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.

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.
       )

      .
      .
      .
    )
      
Return to top

Categorical

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <strings>
Is a list of one or more strings any one of which can be assigned to the variable at any given time.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(
         Color Categorical( "black", "green", "green and black", "orange and black" )
         Legs  Categorical( "6", "8" )
         Shape Categorical( "elongated", "round" )
       )

      .
      .
      .
    )
    
Return to top

Continuous

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <low>
Specifies the lowest value that this variable can be assigned.
       <high>
Specifies the highest value that this variable can be assigned.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(
         Percent_Complete Continuous(0 to 100)
         Percent_Complete Continuous(0,100)
         Percent_Complete Continuous(0 100)
       )

      .
      .
      .
    )
      
Return to top

Discrete

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <numbers>
Is a list of one or more numbers, any one of which can be assigned to the variable at any given time.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(
         Legs  Discrete( 6,   8 )
         Wings Discrete( 0.0  2.0 )
       )

      .
      .
      .
    )
        
Return to top

Fuzzy

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <low>
Specifies the lowest value that this variable can be assigned.
       <high>
Specifies the highest value that this variable can be assigned.
       <fuzzySetDeclarations>
Specifies the fuzzy sets defined over this variable.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(
         Percent_Complete Fuzzy(0 to 100) SetDefinitions( ... )
         Percent_Complete Fuzzy(0,100)    SetDefinitions( ... )
         Percent_Complete Fuzzy(0 100)    SetDefinitions( ... )
       )

      .
      .
      .
    )
      
Return to top

List

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <element>
Is an optional list of boolean, number, and string constants. The list may also contain references to built-in and previously declared variable names.

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]


   )
      
Return to top

Numeric

Numeric variables can be assigned any numeric value; internally, they are represented as doubles.

Syntax

   <variableName> [static] Numeric ( <initialValue> )
      

Parameters

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <initialValue>
Is a number that is the initial value of the variable.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(
         NumberOf_Enrollees Numeric(50)
         PercentComplete    Numeric( 0.34 )

         decrementAmount static Numeric(-5.0)
         incrementAmount static Numeric(+10 )
       )

      .
      .
      .
    )
      
Return to top

Object

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.

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

   )
      
Return to top

String

String variables can be assigned any string value. String comparisons are always case sensitive.

Syntax

   <variableName> [static] String ( <initialValue> )
      

Parameters

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <initialValue>
Is a string that is the initial value of the variable.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(

         Size String("Large")
         ErrorMessage String( "Fatal Error" )

       )

      .
      .
      .
    )
      
Return to top

<userType>

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

       <variableName>
Is an identifier that names the variable.
       static
Is an optional keyword that indicates that the variable is not to be reset to its initial value when the ruleset is reset.
       <userType>
Is a user data type that was declared with a UserTypes statement in the processing options section of the ruleset.
       <arg>
Is a list of zero or more arguments to be passed to the constructor of the Java class represented by the data type. If zero arguments are used, the class must have a null constructor. If any arguments are used, the constructor must take the same number and type of arguments. The arguments may be boolean, number, and string constants, as well as references to built-in and previously declared variable names. Please note that all numbers in Able are represented internally as doubles. This means that any numeric argument passed to a constructor is passed as a double, or, if an object is expected, a Double.

Examples

    RuleSet <nameOfRuleSet> (

       Variables(

         foo Puzzle("HardPuzzle") // CTOR takes name
         bar Ring("RingA", 12.0)  // CTOR takes name & diameter

       )

      .
      .
      .
    )
      
Return to top
Able Rule Language master index.
Able RuleSet Editor master index.
Rules package table of contents.

Last modified: Tue Jul 10 07:57:26 Central Daylight Time 2001