To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationList data type

Standard lists

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]

//Using TYPO (version 1.9.7+)
declare myList as list = []
  

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.
get_circular (number index) ⇒ mixed
Gets an element using a circular index, meaning that it will always be index safe. This was formerly called getc in versions prior to ZPE 1.9.10.
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.

Maps

The map or associative array data type is a very powerful one that features a key to value pair mapping.

This mapping allows quick access to a value based on its key. The key can be any data type ranging from a string, to a number or an object.

Associative arrays are used in many functions across ZPE/YASS as return values since they offer a fast way of accessing data.

There are several functions that work specifically on associative arrays in ZPE as well as the associative array itself having many built-in reference functions.

Producing an associative array is done with nearly identical syntax to that of the standard list by just using the square brackets syntax [] from version 1.5. Prior to that associative arrays were created using the { } syntax (now reserved for objects). The empty associative array is represented by [>].

YASS
$a = ["Jamie" => "Balfour", "Michael" => ["Balfour", "October"]]
//The empty map
$b = [=>]

//Using TYPO (version 1.9.7+)
declare myMap as list = [=>]
    

Much like the list data type, the map data type can have mixed types for the values, even with strong typing enabled.

Reference functions

The map data type provides several reference functions that allow for ease of use:

to_string () ⇒ string
Converts (casts) the map to a string
get (mixed key) ⇒ mixed
Gets an item from the map based on its key.
put (mixed key, mixed value) ⇒ map
Adds an item to the map.
remove (mixed key) ⇒ map
Removes an item based on its key.
Comments

There are no comments on this page.

New comment
Reply
Code previewClose
Feedback 👍
Comments are sent via email to me.