AutolangDocs

Variables

Variables store values in Autolang. Use val (or its alias let) for immutable bindings, and var for mutable bindings.

Declaration & Immutability

The compiler infers the variable type automatically from the assigned value, or you can provide an explicit type annotation. Favor immutable val declarations to keep data flow predictable and safe for AI orchestration.

// Immutable variable val orderId = "ORD-8902" // Keyword 'let' is supported as an alias of 'val' let transactionRef = "TX-5541" // Mutable variable var retryAttempts = 0 retryAttempts += 1 // Explicit type declaration val timeoutSeconds: Int = 30 val taxRate: Float = 0.08

Core Types

TypeDescription
Int64-bit signed integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
Float64-bit double-precision floating-point number.
BoolBoolean value: true or false.
CharFirst-class character literal enclosed in single quotes (e.g. 'A').
StringSequence of characters enclosed in double quotes or triple quotes.
AnyTop type that can represent any Autolang value.

Deferred Initialization

A val can be declared without an initial value if it is guaranteed to be assigned exactly once across all conditional execution paths before being read.

val customerTier = "ENTERPRISE" val processingFee: Int if (customerTier == "ENTERPRISE") { processingFee = 0 } else { processingFee = 25 } println("Assigned fee: " + processingFee)

Nullable Types & Non-Null Assertion

Types in Autolang are non-nullable by default. Append ? to permit null. The non-null assertion operator ! verifies that a nullable expression is not null at runtime.

val secondaryContact: String? = null val primaryContact: String? = "ops@enterprise.com" if (primaryContact != null) { // Smart casting converts primaryContact from String? to String val emailLength = primaryContact.length println("Primary contact length: " + emailLength) } val guaranteedValue: String = primaryContact! println("Contact: " + guaranteedValue)

Destructuring Declarations

Autolang supports destructuring assignments for arrays and pairs directly into multiple variables. Unused components can be discarded with the wildcard _.

// Destructuring array elements val coordinates = [100, 250] val (posX, posY) = coordinates println("X: " + posX + ", Y: " + posY) // Mutable destructuring var (stateCode, statusCode) = [1, 200] stateCode = 2 // Pair destructuring val productEntry = "SKU-99" to 49.99 val (sku, unitPrice) = productEntry println("Item " + sku + " costs " + unitPrice)

Global Scope Resolution

When a local variable or class member shares the same identifier as a top-level global variable, use the :: prefix to explicitly resolve the global binding.

var systemStatus = "NORMAL" class MonitorService { var systemStatus = "INSPECTING" fun report() { println("Local status: " + systemStatus) println("Global status: " + ::systemStatus) } } MonitorService().report()