6 Data Types

Like in other programming languages, in the Rule Language different data types are defined which are described below.

Data Type

Description

anyvalue

This data type is an arbitrary data type. Only by current allocation it gets its actual data type. In a value defined with this data type everything can be saved. On inquiring it is important which kind of value has been saved last.

attribute

This data type is an attribute of the ISA Dialog Manager. It can be assigned all attributes defined by the IDM like .visible or a user-defined attribute.

boolean

This data type represents a boolean value. Its values are either true or false.

class

This data type specifies the class of an object or resource. Values include, for example, classes such as pushbutton, color, function, ...

datatype

This data type represents a data type. Values such as string, object or integer can be stored here.

enum

This data type is an enumeration type. Here values defined by the IDM are stored. This enumeration type is needed for example by the messagebox, if the user presses one of the offered pushbuttons.

event

This data type represents an event in the ISA Dialog Manager. Here values such as select, dbselect, keyand help can be stored.

index

This data type can be used for the addressing of two-dimensional attributes such as the contents of a tablefield. In this data type two whole numbers can be stored, which together address a row and a column, i.e. exactly one cell.

integer

This data type represents a whole number (integer). The value range is from -2 31 to 2 31.

method

This data type represents a method in the ISA Dialog Manager. It can adopt values like :insert, :delete, :clear or :exchange.

object

This data type represents an object in the sense of the IDM, i.e. everything that has a name or can get a name is an object. This applies to all resources, functions, variables, rules and objects.

pointer

This data type represents an unknown type for the Rule Language. It can be used to notice application-specific data in the dialog without that the dialog having to know the contents of the data.

string

This data type represents a character string of any length in the ISA Dialog Manager. The length will be adapted automatically to this type when allocated. In this way, no measures have to be taken by the application..

6.1 Collection Data Types

The following collection data types are allowed in the IDM. Please note that only scalar types are permitted for the addressing as well as for the addressed single values. Therefore a structure of multidimensional lists is not possible.

Table 21-1: Data types for collections

Data Type

Meaning

list

This data type defines a list of arbitrary values in the addressing range 0 … 231. Via 0 the default value is addressed, which is inherited by all list values. This data type is intended and optimized for the manipulation of lists in the Rule Language.

vector

This data type defines a list that contains values of the same type. There is no default value. Therefore, the addressing range is from 1 … 231. This data type is especially intended for communication with object attributes and is not optimized for fast manipulation.

refvec

This data type defines a list that contains only values of type object. The addressing range is 1 … 231 and does not provide a default value. Each object ID is only included once, a null is not added to the list.

matrix

This data type defines a two-dimensional array whose values can be addressed with the index data type. If the specified row (first value of the index) or the column (second value of the index) is 0, it is a default value that is passed on in the addressing order [0,0] → [row,0] → [0,column] → [row,column].

hash

This data type defines an associative array with any scalar addressing range and arbitrary values and an optional default value that is returned for an access that does not contain a key.

Similar to predefined vector and matrix attributes like .content[], .userdata[] etc. an expansion of collections directly after their last element is possible and allowed.

However, it is not possible to use these collection data types for user-defined attributes. User-defined and predefined attributes do not have a unique assignment (attributes exist on an object in both a scalar and a field variant) and allow for unindexed access to the default value.

6.1.1 Syntax of Expressions

List and Hashes

Collections with the data types hash, list, matrix, refvec or vector can be defined using the following syntax within the rule code. A definition in the static part of a dialog or module is not possible with expressions, only constant values may be used. Without explicitly specifying a list data type, a list of the data type list is created. When the reference operator => is used, a hash (associative array) is automatically created, with the expression before => defining the key or index, and the second defining the value.

Attention

For compatibility reasons, index expression takes priority. Thus, to build a two-element list of two integer values, the list data type should be prepended.

Syntax

<list> = [ <data type> ] '[' [ <expression> { ',' <expression> } ] ']'
<hash list> = [ <data type> ] '[' [ <expression> '=>' <expression>
    { ',' <expression> '=>' <expression> } ] ']'

Examples

[1, .xleft, 17+4, Wi.Pb]
["CBS" => 2, itoa(7) => 7]
matrix[ [1,1]=>"first name", [1,2]=>"last name", [1,3]=>"telephone no." ]

6.1.2 List Size and Default Values

In principle, each collection data type has a current size, which results from the values set. There are no value gaps in this currently valid indexing range, only unset values (see also the descriptions of itemcount(), countof()).

In order to achieve consistency with the previous static local variables, the data types hash, list and matrix allow for a default value.

This is displayed at unset value positions within the currently valid indexing range up to the current size. For hash data types, if the default value is set, it is returned for all possible indexings.

The sequence of access to the default values for an unset value at the position <row>,<col> in a matrix M is M[<row>,<col>]M[0,<col>] → M[<row>,0]M[0,0].

The access sequence to the default value for an unset value at <index> in a list L is L[<Index>]L[0].

6.1.3 Access and Assignment of Collections

The indexed values (items) of a collection are accessed via the [] operation, just as known for local variables or predefined and user-defined attributes.

Without the [] operation, the entire value is fetched or set.

Attention

It should be noted that accessing a user-defined or predefined attribute without the [] index fetches or sets the default value or scalar attribute. To fetch or set all values of an attribute, the functions getvector() or setvector() should be used.

Examples

variable list Primes := [2,3,5,7,11,13];
variable vector[integer] Numbers;
variable hash Months := [1=>"Jan", 2=>"Feb", 3=>"Mar"];

print Primes[1];
Months[4] := "Apr";
Numbers := Primes;
Primes[0] := -1;
Primes := [17, 19, 23];

Output of collections via print or sprintf() is also possible. However, no default values are output. For the data types hash and matrix the output is including the index.

Specific Features of refvec

It should also be noted that the refvec data type is handled in a special way because it ensures uniqueness of the values and does not store null values.

With an indexed assignment of an already existing object ID, the object ID at this position is replaced and afterward uniqueness is ensured, which may also result in a shift of the already existing object ID to another position and a reduction of the refvec list.

In case of an indexed assignment of a null, the object ID is deleted from the refvec list and the following object IDs advance, which in turn results in a reduction of the refvec list.

6.1.4 Automatic Conversion

In assignments or parameter calls, collections are automatically converted to the required list type. All values without index are copied in their natural order, including the default values if possible, e.g. [0] for a list variable will be passed on if the target type also has a default value.

Exception

When assigning a hash with index data type to a matrix, the index will be taken over. With the reverse assignment of a matrix to a hash, the index will also be transferred. To prevent this, the built-in function values() should be used.

6.1.5 Performance

In general, it should be considered that the use of collections (entire values) within expressions initially requires the values to be copied, but then in reading operations only references of this list are used, i.e. without further copying. This ensures the necessary performance when working with collections. Passing on to application functions or manipulation by built-in functions, however, requires another copy action, possibly with a code page conversion of string values.

For this reason, it should be kept in mind that complex expressions that process collections may well temporarily lead to large amounts of data. Coding and splitting of expressions should take into account the maximum list sizes.

6.1.6 Local and Global Variable

The collection data types are available for local and global variables. It is also possible to initialize a global collection with constant values.

Until now, local, static variables could also be an array or an associative array, which only could be initialized in a very limited way. Collection data types are now allowed for both local and local static variables. The initialization expression is no longer restricted.

Attention Behavior Change

The existing notation of arrays and associative arrays for static local variables is still allowed and mapped to the data types list or hash. The static initialization via .<identifier>[<index>] := <value>; after the variable part is no longer possible to ensure consistency with other local variables! The initial value sets the entire value of the variable, not just the default value!

Example

dialog D

variable hash Prices := [ "iMac" => 1300, "Samsung Tab" => 300 ];
variable vector[string] Weekdays := ["Mon","Tue","Wed"];

on dialog start
{
  variable string Stations[integer] := [1=>"ABC", 2=>"CBS"];
  variable hash Stations2 := [3=>"NBC", 4=>"HBO"];
  static variable list AllStations := join(Stations,Stations2);
  /* No longer allowed:
   * variable string Stations[integer] := "UNKNOWN";
   * .Stations[1] := "ABC";
   * or
   * static variable integer AssArray[string] := -1;
   * Instead possible:
   * static variable integer AssArray[string] := [nothing=>-1];
   */
  exit();
}

6.1.7 Relational Operators

For collections, only the relational operators = and <> are allowed.

Equality prevails under the following conditions:

  1. The data type must be the same.
  2. All contained values or index/value pairs must be equal, including the default values.
  3. The number of values contained and their positions must be the same.

Comparison between a string and a text ID is done on a string basis.

When using relational operators, particular attention should be paid to the data type.

Example

dialog D
window Wi {
  listbox Lb {
    .content[1] "Sat";
    .content[2] "Sun";
  }
}
on dialog start {
  variable list WeekendDays := ["Sat", "Sun"];
  variable hash DayNumber := ["Sat"=>6,"Sun"=>7];
  variable list Days;

  print WeekendDays = getvector(Lb, .content);
  print vector["Sat","Sun"] = getvector(Lb, .content);
  print values(WeekendDays) = values(getvector(Lb, .content));
  print WeekendDays = keys(DayNumber);
  Days := WeekendDays;
  WeekendDays[0] := "??";
  print Days=WeekendDays;
  exit();
}

Output

false => Different data types (list<>vector)
true
true
true
false => WeekendDays has a default value, but Days does not!

6.1.8 Uninitialized variables

As before, the IDM behaves differently when accessing uninitialized values. If an uninitialized local or static variable is accessed, nothing is returned. When accessing an uninitialized global variable ( equivalent to a variable object) or a user-defined attribute, access is denied with a cannot get value error.