A tuple is a sequence of values identified and accessed by number within the sequence. Different values within a tuple may be of different types. Tuples are the simplest and cheapest of Mythryl datastructures. It is normal and encouraged for a Mythryl program to create and discard millions of tuples during a run; the Mythryl compiler and runtime are optimised to support this. At the implementation level, a tuple is just a sequence of values packed consecutively into a chunk of RAM.
A tuple is constructed by listing a comma-separated sequence of values in parentheses, and accessed using the operators #1, #2, #3 ... to access the first, second and third slots (and so on):
linux$ my eval: t = (1, 2.0, "three"); # Construct a tuple. (1, 2.0, "three") eval: #1 t; # Access first field in tuple. 1 eval: #2 t; # Access second field in tuple. 2.0 eval: #3 t; # Access third field in tuple. "three"
In practice, tuple elements are usually accessed via pattern-matching:
linux$ my eval: t = (1, 2.0, "three"); eval: my (int, float, string) = t; # Assign individual names to the tuple fields. eval: int; 1 eval: float; 2.0 eval: string; "three"