Expressions
Every operator in Tact forms an expression, but there’s much more to uncover as Tact offers a wide range of expressive options to choose from.
Literals
Literals represent values in Tact. These are fixed values—not variables—that you literally provide in your code. All literals in Tact are expressions themselves.
You can also call extension functions defined on certain primitive types corresponding to literals right on the literal values:
Integer literals
Integer literals can be written in decimal (base ), hexadecimal (base ), octal (base ) and binary (base ) notations:
-
A decimal integer literal is a sequence of digits ().
-
A leading (or ) indicates a hexadecimal integer literal. They can include digits () and the letters and . Note, that the case of a character does not change its value. Therefore: = = and = = .
-
A leading (or ) indicates a octal integer literals. They can include only the digits .
-
A leading (or ) indicates a binary integer literal. THey can only include the digits and .
Some examples of integer literals:
Read more about integers and Int
type on the dedicated page: Integers.
Boolean literals
The Bool
type has only two literal values: true
and false
.
Read more about booleans and Bool
type in the dedicated chapter: Booleans.
String literals
A string literal is zero or more characters enclosed in double ("
) quotation marks. All string literals are objects of String
type.
Tact strings support a range of escape sequences starting with a backslash \\
character:
\\
— literal backslash\"
— double quote\n
— newline\r
— carriage return\t
— tab\v
— vertical tab\b
— backspace\f
— form feed\x00
through\xFF
— code point, must be exactly two hex digits long\u0000
through\uFFFF
— Unicode code point, must be exactly four hex digits long\u{0}
through\u{FFFFFF}
— Unicode code point, can be from to hex digits long
null
literal
The null
value is written with a null
literal. It’s not an identifier and doesn’t refer to any object. It’s also not an instance of a primitive type. Instead, null
represents a lack of identification and the intentional absence of any value.
Read more about working with null
on the dedicated page: Optionals.
Identifiers
An identifier is a sequence of characters in the code that identifies a variable, constant, map and a function, as well as a Struct, Message, contract, trait, or their fields and methods. Identifiers are case-sensitive and not quoted.
In Tact, identifiers can contain latin lowercase letters (a-z
), latin uppercase letters (A-Z
), underscores (_
) and digits (), but may not start with a digit. An identifier differs from a string in that a string is data, while an identifier is part of the code.
Note, that when identifiers for primitive types start with an uppercase letter. Used-defined composite types, such as Structs and Messages also must be capitalized.
Instantiation
You can create instances of the following types:
Field access
You can directly access fields of the following types:
Extension function call
Extension functions are defined only on specific types. They can be called similar to method calls in many other languages:
Static function call
Anywhere in the function body, a global static function or an internal function of a contract can be called:
initOf
Expression initOf
computes initial state (StateInit
) of a contract:
Where StateInit
is a built-in Struct, that consists of:
Field | Type | Description |
---|---|---|
code | Cell | initial code of the contract (the compiled bytecode) |
data | Cell | initial data of the contract (arguments of init() function of the contract) |