Variables
Declaring variables
Section titled “Declaring variables”Declare variables with let. Uninitialized variables are nil.
let name = "Ada"let age = 36let score // nil
age = 37 // reassignmentConstants (convention)
Section titled “Constants (convention)”Use UPPER_SNAKE_CASE for values that should not change. Praia warns on reassignment:
let MAX_RETRIES = 3let BASE_URL = "https://api.example.com"
MAX_RETRIES = 5 // Warning: reassigning constant 'MAX_RETRIES'This is a convention, not a hard error — the reassignment still happens, but the warning signals a likely mistake. Single-letter names like N or X do not trigger the warning.
Destructuring
Section titled “Destructuring”Unpack arrays and maps into variables in a single let statement.
Array destructuring
Section titled “Array destructuring”let [a, b, c] = [1, 2, 3]print(a, b, c) // 1 2 3
let [first, ...rest] = [1, 2, 3, 4, 5]print(first) // 1print(rest) // [2, 3, 4, 5]Missing elements become nil:
let [x, y, z] = [1, 2]print(z) // nilMap destructuring
Section titled “Map destructuring”let {name, age} = {name: "Ada", age: 36}print(name, age) // Ada 36Rename with key: varName:
let {name: userName, age: userAge} = {name: "Ada", age: 36}print(userName) // AdaRest collects remaining keys:
let {name, ...other} = {name: "Ada", age: 36, lang: "Praia"}print(other) // {age: 36, lang: "Praia"}Spread operator
Section titled “Spread operator”The ... operator spreads arrays and maps into literals.
Array spread
Section titled “Array spread”let a = [1, 2, 3]let b = [4, 5, 6]let combined = [...a, ...b] // [1, 2, 3, 4, 5, 6]let withExtra = [0, ...a, 99] // [0, 1, 2, 3, 99]Map spread
Section titled “Map spread”let defaults = {host: "localhost", port: 8080}let overrides = {port: 3000, debug: true}let config = {...defaults, ...overrides}// {host: "localhost", port: 3000, debug: true}Later spreads override earlier keys.
Spread in function calls
Section titled “Spread in function calls”func add(a, b, c) { return a + b + c }let args = [1, 2, 3]print(add(...args)) // 6This enables generic function wrappers:
func wrapper(fn) { return lam{ ...args in fn(...args) }}