(T1, T2, ...). They occupy multiple TVM stack entries sequentially and are serialized in the same order. For example, (int, slice) represents two values following one another.
Tensors are anonymous structures and behave identically. Large tensors are impractical — use structures whenever possible.
In many general-purpose languages, syntax
(A, B, C, ...) is used for tuples, not tensors, which are a different type. However, in TON, a tuple is a distinct TVM primitive that has its own syntax [a, b, ...] and semantics.For example, a tensor (int, int, int) represents three integers on the stack, whereas a tuple [int, int, int] is a single stack entry that contains three integers within itself.Component access
Usetensor.{i} to access tensor components by their index:
Tensors as anonymous structures
The structUser below and a tensor (int, slice) have identical stack layouts and serialization rules:
obj.{field} is equivalent to tensor.{i}:
Destructuring assignments
The following syntax is valid:(10, 20) assigned to two variables:
("abcd", (10, 20)) and ("abcd", 10, 20) are placed identically as three stack entries containing the values "abcd" (as a slice), 10, and 20, respectively. However, Tolk treats (slice, (int, int)) and (slice, int, int) as distinct types.
_ can be used on the left side to discard a destructured value:
Empty tensors
Empty tensors are valid values:In some programming languages, an empty value is known as unit, and functions that don’t return a value can be said to “return a unit”. Tolk uses a special type called
void for this purpose.The void type is not compatible with empty tensors, despite both indicating the absence of a value.