Language basics
Every statement ends where the next one begins — semicolons are optional and rarely used in practice. Comments come in two forms:
// a line comment, runs to the end of the line
/* a block comment,
can span multiple lines */
Declaring something always needs the ton. prefix, followed by a type keyword and a name:
ton.int age = 25
ton.function greet(name) {
print("Hello, " + name)
}
Referring to something already declared — reading a variable, reassigning it, calling a function, or naming a function parameter — accepts either the prefixed or the bare form; the parser treats ton.x and x identically once x exists in scope:
ton.int age = 25
print(ton.age) // ok
print(age) // also ok — same variable
age = age + 1 // also ok
Function parameters are conventionally written without the prefix (ton.function greet(name) { ... }, not ton.function greet(ton.name)), matching every example in this document and in exemples/.
A bare assignment can only reassign an existing variable — age = 5 fails with "was never declared" unless something already declared age earlier. To introduce a brand-new variable you always need the full ton.<type> name = value form.
ton.let, ton.var and ton.const — declare a variable without a fixed type with ton.let (ton.var is a synonym). ton.const does the same but forbids reassigning it later: PI = 3 after ton.const PI = 3.14 is a runtime error. Typed declarations (ton.int, ton.string, ...) still check the type of the initial value.
ton.let anything = 42
anything = "now a string" // fine: ton.let has no fixed type
ton.const MAX_USERS = 100
MAX_USERS = 5 // Error: Cannot reassign 'ton.MAX_USERS': it was declared with ton.const.
Number literals — besides 42 and 3.14: 1_000_000 (underscores are ignored), 1e9 / 2.5e-3 (exponent), 0xFF (hexadecimal), 0b1010 (binary), 0o755 (octal).
Semicolons are optional; use them to put several statements on one line: self.x = x; self.y = y.