Types
| Type | Declaration | Example |
|---|---|---|
| Integer/float | ton.int / ton.float | ton.int x = 5 |
| String | ton.string | ton.string s = "hi" |
| Boolean | ton.bool | ton.bool ok = true |
| Array | ton.array | ton.array a = [1, 2, 3] |
| Dictionary | ton.dict | ton.dict d = {a: 1} |
| HTML | ton.html | ton.html page = "<h1>Hi</h1>" |
| Function | ton.function | ton.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:
| Declaration | Meaning | Example |
|---|---|---|
ton.let / ton.var | Any type, can change later | ton.let x = 5 |
ton.const | Any type, can't be reassigned | ton.const PI = 3.14 |
ton.<ClassName> | An instance of that class (or of a subclass), or nil | ton.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.