Menu

Compact arrays

Mark Anthony Taylor (Shyreman)

Arrays are C-compatible compact sequences of structures.

The syntax is:

(array <type> <name> <capacity>)

Example: (array Int32 q 4) // Creates an array of 32-bit integers called q.

type gives the type name, which can be a primitive, structure, archetype or interface.
name gives the local variable name, which follows the same identifier rules as other local variables.
capacity gives the maximum number of elements that the array can store.

Arrays cannot grow beyond their capacity. This was decided to reflect the fact that all computer
memory and processing power is limited, and Sexy is designed for speed and memory efficiency
so respects the host machine's limitations.

The capacity and length of the array can be retrieved by assigning using the pseudo methods Capacity
and Length of the array.

(Int32 capacity = q.Capacity)
(Int32 length = q.Length)

Items are pushed onto the array using the pseudo method Push

(q.Push 1812)

Items are retrieved by using an s-expression that contains the array name followed by the zero based index.

(Int32 overture = (q 0))

Using the syntax (<name> <index> <value>) one can set particular entries.

(q 0 1776)    // q[0] is now 1776

// Items with the highest index are popped off using method Pop which returns no output

(q.Push 1812)
(q.Push 1813) // array now has 2 elements, 1812 and 1813
(q.Pop) // Pop off q[1] = 1813 from the array

// Using PopOut assigns the value to a variable

(q.Push 1812)
(Int32 overture = (q.PopOut))

Related

Wiki: Content