On this page:

Sequence Syntax and Semantics

Sequences are variable-length collections of elements:

{zcode:slice}
sequence<Fruit> FruitPlatter;
{zcode}

A sequence can be empty — that is, it can contain no elements, or it can hold any number of elements up to the memory limits of your platform.

Sequences can contain elements that are themselves sequences. This arrangement allows you to create lists of lists:

{zcode:slice}
sequence<FruitPlatter> FruitBanquet;
{zcode}

Sequences are used to model a variety of collections, such as vectors, lists, queues, sets, bags, or trees. (It is up to the application to decide whether or not order is important; by discarding order, a sequence serves as a set or bag.)

Using Sequences for Optional Values

One particular use of sequences has become idiomatic, namely, the use of a sequence to indicate an optional value. For example, we might have a Part structure that records the details of the parts that go into a car. The structure could record things such as the name of the part, a description, weight, price, and other details. Spare parts commonly have a serial number, which we can model as a long value. However, some parts, such as simple screws, often do not have a serial number, so what are we supposed to put into the serial number field of a screw? There are a number of options for dealing with this situation:

See Also