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.
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.
|An array containing the 2nd through 5th elements|
|The number of elements in the array|
|An array representing the first section of the array when divided into two sections|
|An array representing the third section of the array when divided into three sections|
|An array representing the 2nd item in each section of the array when divided into sections with 3 parts in each|
|An array representing the 2nd and 3rd sections of the array when divided into four sections|
|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|
|An array representing two copies of the 5th element in the array|
|An array representing the array repeated 6 times|
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 (
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 processIntegerTuple value, value, 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 -> secondElement helper process secondElement extension setup -> element: Element extract @elements, @elements -> assign to element, assign to @elements extension setup helper: ComplexObject -> element: Element extract @elements, @elements -> assign to element, assign to @elements helper process element
A String is an array of Characters. It functions exactly as an array, but has quotation-based syntax (
"Goodbye!") when printing and describing it literally.
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.