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:

- Is required
- Must contain at least one variable declaration
- Must not redefine a built-in variable
- Declares global variables
- Each variable name must be unique

Variable declaration statements:

- Boolean
- Categorical
- Continuous
- Discrete
- Fuzzy
- List
- Numeric
- Object
- String
- <userType>

### 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

       [static] Boolean <variableName> = new 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(
             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.
           )

          .
          .
          .
        )

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

       [static] Categorical <variableName>  = new 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(
             Categorical Color = new Categorical( "black", "green", "green and black", "orange and black" );
             Categorical Legs = new Categorical( "6", "8" );
             Categorical Shape = new 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

       [static] Continuous <variableName> = new 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(
             Continuous Percent_Complete = new Continuous(0 to 100);
             Continuous Percent_Complete = new Continuous(0,100);
             Continuous Percent_Complete = new 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

       [static] Discrete <variableName> = new 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(
               Discrete Legs = new Discrete( 6, 8 );
               Discrete Wings = new 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, 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

  <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(
               Fuzzy Percent_Complete = new Fuzzy(0 to 100) { ... } ;
               Fuzzy Percent_Complete = new Fuzzy(0,100) { ... };
               Fuzzy Percent_Complete = new Fuzzy(0 100) { ... };
             )

            .
            .
            .
          )

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

  <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 or variables. The list may contain references to built-in and previously declared variable names.

  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]

         )

  Return to top

  ### Numeric

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

  Syntax

         [static] Numeric <variableName> = new 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(
               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);
             )

            .
            .
            .
          )

  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

         [static] Object <variableName> = new 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(

               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

         )

  Return to top

  ### String

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

  Syntax

         [static] String <variableName> = new 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(

               String Size = new String("Large");
               String ErrorMessage = new String("Fatal Error");

             )

            .
            .
            .
          )

  Return to top

  ### import <package-spec><userType>

  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

  <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 import statement in the 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(

               Puzzle foo = new Puzzle("HardPuzzle"); // CTOR takes name
               Ring bar = new 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