tuple— a dynamic tuple with unknown shape[T1, T2, ...]— TVM tuple with known shape
In most languages,
(v1, v2, ...) denotes a tuple.
In TON, however, a “tuple” is a specific TVM primitive.
For this reason, (v1, v2, ...) in Tolk is called “a tensor”.
Read about tensors.tuple: dynamic tuples
A TVM tuple allows storing from 0 to 255 elements in one stack slot. Push elements into a tuple:
t.get(idx), the type must be provided explicitly or inferred:
tupleVar.{i} is also permitted when the type is evident:
set() does not create new elements; it only updates existing ones.
If idx is out of bounds in get() or set(), an exception is thrown.
last(), set(), pop(), etc. IDE will suggest them after a dot.
Only primitives can be placed into a tuple
An attempt to callt.push(somePoint) will raise an error: only single‑slot values can be added and retrieved.
Convert an object to a tuple and back
Tolk provides built-in generic methodsT.toTuple() and T.fromTuple().
If a value occupies N stack slots, the resulting tuple has size N.
Typed tuples [T1, T2, ...]
Use this syntax to describe a tuple with a known shape:
(T1, T2, ...), but all values are stored in a single stack slot.
Non-primitive values are also not permitted.
A typed tuple may be destructured into multiple variables:
Lisp-style lists
Lisp-style lists are nested two-element tuples:[1, [2, [3, null]]] represents the list [1, 2, 3].
An empty list is conventionally represented as null.
From the type‑system perspective, it’s tuple? with dynamic contents, not a special type.
It was a common pattern in old contracts, but now it’s almost unused.
Its primary remaining use case is to return more than 255 elements.
Lisp‑style lists can be processed using the following stdlib module:
Tuples vs tensors
A tensor is(T1, T2, ...) — multiple values in parentheses.
The primary distinction is the stack layout: a tuple is a single stack slot,
whereas tensor components are placed one by one.
For example, (coins, builder, int?) occupies 3 slots, but [coins, builder, int?] — only one.
Accessing tupleVar.{i} produces TVM asm {i} INDEX, but tensorVar.{i} is just stack shuffling.
Read about tensors.