Skip to main content

Tuple

rascal-0.40.17

Synopsis

Tuple values.

Syntax

< Exp₁, Exp₂, ... >

Types

Exp₁Exp₂...< Exp₁, Exp₂, ... >
T₁T₂...tuple[T₁, T₂, ... ]

Description

A tuple is a sequence of elements with the following properties:

  • Each element in a tuple (may) have a different type.

  • Each element of a tuple may have a label that can be used to select that element of the tuple.

  • Each tuple is fixed-width, i.e., has the same number of elements.

Tuples are represented by the type tuple[T₁ L₁, T₂ L₂, ...], where T₁, T₂, ... are arbitrary types and L₁, L₂, ... are optional labels.

The following operators are provided for tuples:

Examples

rascal>tuple[str first, str last, int age] P = <"Jo","Jones",35>;
tuple[str first,str last,int age]: <"Jo","Jones",35>
rascal>P.first;
str: "Jo"
---
Jo
---
rascal>P.first = "Bo";
tuple[str first,str last,int age]: <"Bo","Jones",35>