tuple

tuple, language construct

Tuples group multiple values into a single scalar.

Example

myTuple = (1, "y")
a, b = myTuple

show summary "Tuple" with
  a
  b

This outputs the following list:

Label Value
a 1
b y

Example (unpacking)

Tuple unpacking works in plain assignment, not only in loop lists.

Values = ("B", "C", "D")
V1, V2, V3 = Values

show summary "Unpack" with
  V1
  V2
  V3

This outputs the following list:

Label Value
V1 B
V2 C
V3 D

The ... operator can also be used in tuple assignment to expand tuple values. See ... for the full operator reference.

Values = ("B", "C", "D")
All = ("A", ...Values, "E")
V1, V2, V3, V4, V5 = All

show summary "All" with
  V1
  V2
  V3
  V4
  V5

This outputs the following list:

Label Value
V1 A
V2 B
V3 C
V4 D
V5 E

Example (returning tuples)

def pure bump(x: number) with
  return (x, x + 1)

a, b = bump(42)

show summary "Bump" with
  a
  b

This outputs the following list:

Label Value
a 42
b 43

Tuples can also be returned from def process and assigned into multiple vectors.

table T = with
  [| as N |]
  [| 1 |]
  [| 2 |]
  [| 3 |]

def process pairSum(n: number) with
  keep acc = 0
  acc = acc + n
  return (acc, n)

T.A, T.B = pairSum(T.N) scan T.N

show table "Pairs" with
  T.N
  T.A
  T.B

Remarks

Use _ to discard a tuple component when deconstructing. User-defined functions do not accept tuple parameters.

User Contributed Notes
0 notes + add a note