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 documentationLists & arrays

Lists are a simple name for an array in ZPE. Unlike standard arrays in languages such as Java or C, they can expand as necessary. Version 1.6.7 finally added fixed size lists (arrays).

$a = [44, 32, 99]
print([4, 9, 3])

As of version 1.6.7 fixed size arrays are now possible:

$a = [0] * 4
$b = ["Hello world"] * 3

The previous example will add the number 0 four times to the first list and then add "Hello world" three times to the second list.

The difference between a list and an array (added in version 1.6.7) is that arrays have a fixed size whereas lists can be increased (or decreased) in size very easily. Arrays have the advantage of index existence, that is, one can be assured that such an index does exist.

Other languages use arrays and do not offer a list type and as a result, from an educational perspective, arrays are better suited as a teaching tool.

Negative indices and ranges

ZPE 1.8.6 (Younis) added support for negative indices. These will work backward from 0, e.g. -1 will be the last element within the list and -2 will be the penultimate element.

$l = [0, 1, 2, 3]

For the sake of preventing accidental accessing a negative index that does not exist, for example applying -53 here, ZPE sanitises any negtaive index access automatically.

When the INDEX_SAFETY setting is set to on negative indices cannot be used.

ZPE 1.8.6 also added ranges of indices. This allows you to obtain a list of items from the list very quickly.

$l = [0, 1, 2, 3]

Note that the range is inclusive and includes both the first index and the second index when using this range, so the above example would return [1, 2, 3].


There are no comments on this page.

New comment
Provide feedback on this page
Comments are sent via email to me.