Variables & Types
Learn about variable declaration, type annotations, and the primitive types available in Soli.
Variable Declaration
Variables are declared using the let keyword. Soli uses block scoping.
let
Declares a mutable variable with optional type annotation.
let x = 10
let name = "Soli"
let is_active = true
Type Annotations
You can explicitly specify types for documentation, IDE support, and runtime validation.
# Explicit type annotations
let name: String = "Alice"
let age: Int = 30
let temperature: Float = 98.6
let is_active: Bool = true
let scores: Int[] = [95, 87, 92]
let user: Hash = {"name": "Alice", "age": 30};
Primitive Types
Soli provides six primitive types:
Constants
const
Use const for values that should never change.
const MAX_CONNECTIONS = 100
const DEFAULT_TIMEOUT = 30
const PI = 3.14159265359
# const values cannot be reassigned
# MAX_CONNECTIONS = 200; # This would cause an error
Scope
Variables in Soli are block-scoped:
let x = 1
if true
let y = 2 # y only visible in this block
let x = 3 # shadows outer x
print(x) # Output: 3 (inner x)
end
print(x) # Output: 1 (outer x)