(T1, T2, ...).
For example, (int, slice) — two values one by one.
Large tensors are generally impractical; structures are typically more suitable.
Essentially, structures are named tensors.
In most languages,
(v1, v2, ...) is called a tuple.
However, in TON, a “tuple” refers to a specific TVM primitive.
For this reason, (v1, v2, ...) in Tolk is called “a tensor”.Syntax tensorVar.{i}
Access tensor components for reading and writing:
Structures as named tensors
StructUser below and a tensor (int, slice) have identical stack layouts and serialization rules:
obj.{field} is equivalent to tensorVar.{i}:
Destructuring at assignment
The following syntax is valid:(10, 20) assigned to two variables:
_ can be used on the left side:
Empty tensors are also valid values
In some languages, an empty value is called “unit”, and functions that return no value conceptually return a “unit” value.
In Tolk, a special type “void” is used for that (like in TypeScript).
void and () are not compatible, although they both hold no value.Tensors vs tuples
A tuple is a special TVM primitive: it is a dynamic container capable of holding multiple values within a single stack slot. For example, a tensor(int, int, int) is “3 integers on the stack”, whereas a tuple with 3 integers is “one tuple on the stack”.
Tolk supports the tuple type. Read about tuples.