Data Types
Praia has 7 types:
| Type | Examples | Notes |
|---|---|---|
nil | nil | The absence of a value |
bool | true, false | |
int | 42, 0xFF, 0b1010, 0o17 | 64-bit integer (exact up to 2^63). Supports hex, binary, octal. |
float | 3.14, 1e3, 2.5e-4 | Double-precision float. Supports scientific notation. |
string | "hello" | UTF-8, supports interpolation, escape sequences, and Unicode (\u{...}) |
array | [1, 2, 3] | Ordered, mixed-type, reference semantics |
map | {name: "Ada"} | Key-value pairs, reference semantics |
function | func add(a, b) { ... } | First-class, supports closures |
Use type() to check a value’s type at runtime:
print(type(42)) // intprint(type(3.14)) // floatprint(type("hi")) // stringprint(type([1, 2])) // arrayprint(type({a: 1})) // mapNumber literals
Section titled “Number literals”Integers
Section titled “Integers”Integers support multiple bases and underscores as visual separators:
42 // decimal0xFF // hex0b1010 // binary0o755 // octal1_000_000 // underscores ignored (readability)0xFF_FF // works in any baseFloats
Section titled “Floats”Floats support decimal points and scientific notation:
3.14 // decimal float1e3 // 1000.0 (scientific notation)2.5e-4 // 0.000251_000.5 // separators in floats tooInteger overflow automatically promotes to float rather than wrapping.
Arithmetic rules
Section titled “Arithmetic rules”int + int,int - int,int * int,int % intproduceint- Anything involving a float produces
float /always returnsfloat:7 / 2gives3.5
42 + 8 // 50 (int)42 + 0.5 // 42.5 (float)7 / 2 // 3.5 (always float)7 % 2 // 1 (int)Integers are 64-bit, so they are exact up to 2^63:
let big = 9007199254740993print(big + 1) // 9007199254740994 (exact)Ints and floats compare by value: 42 == 42.0 is true.
Truthiness
Section titled “Truthiness”Only nil and false are falsy. Everything else — including 0, "" (empty string), and [] (empty array) — is truthy.
if (0) { print("truthy") } // prints (0 is truthy)if ("") { print("truthy") } // prints (empty string is truthy)if ([]) { print("truthy") } // prints (empty array is truthy)if (nil) { print("truthy") } // does not printif (false) { print("truthy") } // does not printTo check for empty strings or arrays, use len():
if (len(name) > 0) { print("has name") }if (len(items) > 0) { print("has items") }Type checking with is
Section titled “Type checking with is”The is operator checks types and class hierarchy:
42 is "int" // true"hello" is "string" // true[1, 2] is "array" // true
class Animal {}class Dog extends Animal {}let d = Dog()d is Dog // trued is Animal // true (walks inheritance chain)Supported type strings: "nil", "bool", "int", "float", "string", "array", "map", "function", "instance".