Official ZPE/YASS documentationList data type
The list data type is one of the most powerful data types in ZPE. The list works similar to an array in other languages but unlike a standard array can be either fixed length or countably infinite.
Defining a list is easy:
YASS
$empty_list = [] $some_list = [1, 2, 3, 4]
There are many operations that can be performed on the list but perhaps the most common is simply obtaining an element from the list:
YASS
$some_list = [1, 2, 3, 4] //This will obtain the third element from the list $some_element = $some_list[2]
Defining a fixed-length array is also very easy by just defining in the brackets the default value of the array and then telling the compiler how many elements are needed:
YASS
$some_list = [0] * 5
Reference functions
The list data type provides several reference functions that allow for ease of use:
- to_string () ⇒ string
- Converts (casts) the list to a string
- put (mixed value) ⇒ list
- Puts an element at the end of the list.
- push (mixed value) ⇒ list
- Adds an element to the start of the list.
- getc (number index) ⇒ mixed
- Gets an element using a circular index, meaning that it will always be index safe.
- sublist (number from, number to) ⇒ list
- Gets a sublist of the list.
- remove (number index) ⇒ list
- Removes an element from a list at a specified index.
- length () ⇒ number
- Returns the length or size of the list.
There are no comments on this page.