ESC
Type to search...
S
Soli Docs

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.

// Basic variable declarations
let name = "Alice";           // String
let age = 30;                 // Int
let temperature = 98.6;       // Float
let is_active = true;         // Bool
let nothing = null;           // Null

Type Annotations

You can explicitly specify types for better documentation and type safety.

// 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 five primitive types:

Int

64-bit signed integer

42, -100, 9_000_000
Float

64-bit floating-point

3.14, 0.001, 2.5e10
String

UTF-8 string

"Hello", "Line 1\nLine 2"
Bool

Boolean

true, false
Null

Absence of value

null

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)
}

print(x);           // Output: 1 (outer x)