Skip to main content
Tolk supports first-class functions. Function values have callable types of the form (...ArgsT) -> ReturnT.

First-class functions

Pass a function as a callback:
A function myPlus has the type (int, int) -> int. A function demo, for example, has the type () -> void. Functions can be assigned to variables:

Lambda functions

Tolk supports lambda functions:
Lambda parameter types may be omitted when they can be inferred. In the example above, both a and b are inferred as int from the invokeMath declaration. When parameter types cannot be inferred, they must be specified:
As first-class functions, lambdas can also be returned:
Lambdas are primarily used in general-purpose tooling. They can be combined with generic types and used as nested expressions without restrictions.

Closures (lambdas with captures)

Lambdas capture outer variables, becoming first-class closures:
There is no special use or [&] syntax — capturing happens automatically. Variables are captured by value at the point where the lambda is created, so later mutations of the outer variable do not propagate into the closure:
Closures combine with generics, nesting, and smart casts: a lambda captures the narrowed type of a variable as of the point where it was created.

Low-level TVM continuations

Continuations are executable cells representing TVM bitcode. A callable is a typed continuation. Tolk provides the low-level type continuation. For example, the TVM register c3 contains the smart contract code. Some functions are available in the standard library:

Stack layout and serialization

A callable is backed by the TVM CONT. Callable values cannot be serialized.