Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationTuple data type

The Tuple data type was added in ZPE 1.12.9 (Piper Pine Marten, September 2024). In essence, a tuple is much like a list, except that each value of a tuple is typed. Whilst ZPE introduced array data type some time before the tuple, the array data enforces that all values are of the same type. The tuple data type on the otherhand allows data types to be specified per element. It also has a slightly larger memory overhead.

Tuples are convenient to write and easy to implement. They use the simple bracketed syntax as used in mathematics and logic to represent tuples:

YASS
(10, "Hello world")
  

However, before the previous code could run, we need to have a few other things before it. Unlike lists, for example, they are built in two stages. These stages are:

  • Definition
  • Instantiation

The definition stage of a tuple involves declaring the tuple data types:

YASS
$x = (number, string)
  

After definition, using the exact same variable name as before, the tuple is then instantiated:

YASS
$x = (10, "Hello world")
  

Using tuples

A tuple can be used in the same way as any indexable element, using the subscript syntax:

YASS
$x = (number, string)
$x = (10, "Hello world")
// Should print "Hello world"
print($x[1])
  
Comments
Feedback 👍
Comments are sent via email to me.