Skip to main content
Tolk has first-class functions: they can be passed as callbacks. Such values have callable types: (...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, is () -> void. Assigning functions to variables also works:

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 int, inferred from invokeMath declaration. If they cannot be inferred, the parameter types must be specified:
As first-class functions, lambdas can even be returned:
While lambdas are uncommon in smart contracts, they are useful in general‑purpose tooling. They can be combined with generics of any level and may be nested without restrictions.
Note that lambdas are not closures: capturing outer variables is not supported.

Low-level TVM continuations

Continuations are executable cells representing TVM bytecode. A callable is effectively a typed continuation. Tolk has a type continuation type for low-level purposes. For example, TVM register c3 contains current smart contract code. Some functions are available in stdlib:

Stack layout and serialization

A callable is backed by TVM CONT. It cannot be serialized. For details, follow TVM representation and Serialization.