Notes: Aggregates


Aggregates

As well as providing simple data types such as int and string ICI provides types that contain other objects and allow data structures to be created. ICI provides three aggregate types; set, array and struct. Sets provide an "unordered collection" type, arrays provide an "ordered collection" type and struct objects are dictionary types containing multiple key/value pairs. Each aggregate type may contain objects of different types and aggregate objects will grow dynamically to accomodate new entries.

Aggregate Types

There are three inbuilt aggregate types, each represents a different type of data structure with that structure's inherent behaviour,

Indexing

The indexing operation is fundamental operation in ICI and is especially important with aggregates. Indexing is denoted using the '[]' operator as used for array access in C. Formally the index operator is,

<expression> [<expression> ]

That is, an expression followed by an expression enclosed in brackets. The semantics of indexing are that the result of the second expression is used as a "key" in some type of lookup operation on the object resulting from the first expression. What actually happens depends on the type of the first expression. Each type has its own interpretation of indexing and some types, such as integers, may not be indexed at all.

Sugar

ICI defines the familar dot notation in terms of indexing. This allows many programmers to feel at home with ICI structs and lets them be used in a C-like manner. The syntax name.key (name dot key)is converted to the form name["key"]. I.e, the key is used as a string key in a lookup operation on the object. This convention applies to simple variable names in ICI as the variable scope is implemented in terms of ICI's struct type. A variable name is turned into a string and looked up in the scope struct.