Types

TypeDeclarationExample
Integer/floatton.int / ton.floatton.int x = 5
Strington.strington.string s = "hi"
Booleanton.boolton.bool ok = true
Arrayton.arrayton.array a = [1, 2, 3]
Dictionaryton.dictton.dict d = {a: 1}
HTMLton.htmlton.html page = "<h1>Hi</h1>"
Functionton.functionton.function f() { ... }

ton.int and ton.float are both backed by the same internal double-precision number — TON618 doesn't enforce integer-only storage (see Known limitations). Assigning a plain string literal to a ton.html variable automatically coerces it to HTML (a convenience for route handlers that return markup).

type(x) returns a value's type name as a string: "int/float", "string", "html", "bool", "array", "dict", "nil", or "function".

Since beta-2.0.0:

DeclarationMeaningExample
ton.let / ton.varAny type, can change laterton.let x = 5
ton.constAny type, can't be reassignedton.const PI = 3.14
ton.<ClassName>An instance of that class (or of a subclass), or nilton.Point p = Point(1, 2)

type(obj) returns the class name for an object ("Point"), and "class" for a class itself. Numbers print in their shortest exact form: 0.1 + 0.2 prints 0.30000000000000004, 3.14 prints 3.14 (versions before 2.0 printed 3.140000). Use fixed(x, 2) for a fixed number of decimals.

Edit this page on GitHub