Tuples

Tuples data types are not directly used by the user, they are used as a mechanism to allow functions to return multiple values.

Tuples are expected only when when parsing function return types, and are not used in any other context.

Since Type-C supports anonymous functions and to avoid ambiguity within the compiler, the parenthesis are required to indicate the expressions enclosed are a tuple.

Tuples Values Unpacking

A single variable cannot hold a tuple, but you can unpack a tuple into multiple variables.

Skipping Values During Unpacking

When reading values from a tuple, it is possible to use _ to skip values.

Return statement

When returning a tuple from within a function, the writing is the same if it is an expression function or a statement function declaration, here is a snippet showcasing both cases:

It is important to notice that the comma is used primarly as a separator within Type-C, meaning that stacking expression with a comma will generally result in a compile-time error. The only expection to this is when returning a tuple from a function, meaning right after the function assignment or the return statement.


Kudos! Keep reading!