Collections in Ozark come in three flavors. There are arrays and tuples, which offer powerful subscript-based access to groups of pointers, and there are other pointer-based collection types that can be built with generics.
Arrays
An Array is an immutable, nestable, homogeneous, 1-based ordered list of non-optional objects or values. Arrays can be specified literally using square bracket ([]
) notation, or created sequentially as the output of a repeat loop or repeating "all" statement.
Eligible variables that store arrays may be marked as optional.
inheritance Example method setup helper: ComplexObject create bananas: [Banana]; setup | repeat 12 times helper doSomething twoBananas: bananas[1~2]
Anywhere an array is needed, you can use subscript-based expressions to split and combine arrays.
Example | Meaning |
---|---|
someArray[1] | First element |
someArray[4] | Fourth element |
someArray[-1] | Last element |
someArray[2~5] | An array containing the 2nd through 5th elements |
someArray[*] | The number of elements in the array |
someArray[1/2] | An array representing the first section of the array when divided into two sections |
someArray[3/3] | An array representing the third section of the array when divided into three sections |
someArray[2%3] | An array representing the 2nd item in each section of the array when divided into sections with 3 parts in each |
someArray[2/4+3/4] | An array representing the 2nd and 3rd sections of the array when divided into four sections |
someArray[2/4-2/5] | An array representing the 2nd section of the array when divided into four sections, except for the elements in the 2nd section of the array when divided into five sections |
someArray[5*2] | An array representing two copies of the 5th element in the array |
someArray[*6] | An array representing the array repeated 6 times |
Tuples
A Tuple is an immutable, nestable, heterogenous, 1-based ordered group that may include both values and/or objects. Tuples can be specified literally by separating the values with a comma (,
). Eligible variables that store tuples may be marked as optional, but individual elements of a tuple may not (because that would make it a different tuple). A tuple with only one element is identical to the element itself.
Tuples can be nested or stored in arrays using curly bracket syntax ({
and }
)
Tuples are often used as method inputs and/or outputs, which gives the effect of allowing positional parameters side-by-side with named ones.
inheritance Example @property1: Integer @property2Copy1: Integer @property2Copy2: Integer method instigate helper: HelperObject, value: SomeObject, Integer, Integer value[1] processIntegerTuple value[2], value[3], finalInstruction: false helper getIntegerTuple -> assign to @property1, assign to [@property2Copy1, @property2Copy2]
You can use subscript access on tuples just like on arrays.
Extract & Split
You can use the extract and split keywords on a property or output that contains an array or a tuple. This returns a 2-tuple of the extracted portion and the remaining portion, respectively. split
removes multiple elements, where extract
removes only one.
inheritance Example property @elements: [Element] extension setup helper: ComplexObject extract @elements, @elements[2] -> secondElement helper process secondElement extension setup -> element: Element extract @elements, @elements[2] -> assign to element, assign to @elements extension setup helper: ComplexObject -> element: Element extract @elements, @elements[2] -> assign to element, assign to @elements helper process element
Strings
A String is an array of Characters. It functions exactly as an array, but has quotation-based syntax ("Hello"
, "Goodbye!"
) when printing and describing it literally.
Generics
Arrays & tuples are the only collection types that include subscript-based, direct element access. To build a pointer-based data structure accessible through instance methods, use generics.
Generics allow a class to make use of a type that's not known in advance. The type is specified when the instance of the class is created. See Generics for more information on their syntax and usage.