1.6. Tuples

A tuple is a sequence of at least two values. Orc does not have 0-tuples or 1-tuples.

Tuples are intended to be used for sequences with a fixed length and varying element types, whereas lists are intended to be used for sequences with varying length and a fixed element type.

1.6.1. Syntax

[3]Tuple::= ( Expression , , Expression ) Tuple Size ≥ 2 ]

1.6.2. Constructors

The tuple expression ( E0 ,, En ) publishes the tuple value ( v0 ,, vn ) only if each expression Ei deflates to value vi. Otherwise, it halts silently.

1.6.3. Operations

Notable tuple operations include:

  • Return the tuple element at position index, starting from 0: tuple(index)

  • Return the first element of a pair: fst(tuple)

  • Return the second element of a pair: snd(tuple)

1.6.4. Type

The type of a tuple value (v0 ,, vn) where vi has type Ti, is a tuple type, written (T0 ,, Tn).

1.6.5. Java calls

Orc tuples don't correspond to any Java value, so if a tuple is passed to Java code, it will be as a java.lang.Object of a type not specified here.

1.6.6. Examples

Tuple Selection
{- Unzip a list of tuples into a tuple of lists -}

val squares = [(1,1), (2,4), (3,9), (4,16)]

# ( map(fst,squares) , map(snd,squares) ) 

{-
OUTPUT:
([1, 2, 3, 4], [1, 4, 9, 16])
-}
Fork-Join
{- Print "fork", but wait at least 500ms before printing "join" -}

( Println("fork"), Rwait(500) ) >> Println("join") >> stop

{-
OUTPUT:
fork
join
-}

1.6.7. Related Links

Related Tutorial Sections