Reference > Rule Language > Definitions > set <variable>

Defines a variable in the defintions part of a rule as an object, a collection, or a value.

Example

The following example shows all the variable declaration possibilities in the definitions part of the rule.

 definitions
    // element declaration
    set 'i' to an item ;
    set 'house' to a house 
       where the price of this house is more than 1000 ;
    set 'expensive items' to all items 
       in the items of the shopping cart of the customer 
       where the price of each item is more than 200 ;
    // literal declaration
    set 'category' to Gold ;
    set 's' to "a string" ;
    set 'coll' to { Gold, Silver } ;
    // expression  declaration
    set 'expr' to the price of the car of the customer + 100 ;
    set 'customer age' to the age of the customer ;
    set 'h1' to the house of the customer ;
    set 'h2' to the house of the customer 
       where the price of this house is more than 1000 ;
    set 'items' to the items of the shopping cart of the customer ;
    // variable declaration
    set 'expr2' to 'expr' ;