AutolangDocs

Variables

Variables are containers for storing data values. Use val (immutable) or var (mutable) and assign a value with =.

Syntax

The compiler will infer the type from the assigned value, or you can declare it explicitly. var is mutable; val is immutable.

val variableName = value var variableName = value // Explicit type val variableName: type = value // Wrong: compiler can't infer the type without a value val variableName // Wrong: val is immutable val variableName = 1 variableName = 2

Default Types

TypeDescription
IntWhole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Character literals (e.g. a) are also stored as Int.
FloatFractional numbers. Sufficient for 15–16 decimal digits.
BoolStores true or false.
StringStores a sequence of characters.
AnyStores any object (testing).

Character Literals

In Autolang, there is no separate Char type. Single-quote character literals evaluate directly to their Int (ASCII) values.

val codeA = 'a' // codeA is Int with value 97 val codeB = 'b' // codeB is Int with value 98 println(codeA + 1 == codeB) // Output: true

Nullable Types

Append ? to a type to allow null. Use ! to assert non-null.

val variableName: type? // Nullable, default null var variableName: type? // Nullable, mutable val variableName? = value // Inferred nullable val variableName! = value // Inferred non-nullable

Assignment & Copying

Int values are automatically copied on assignment (passed by value). Other object types are references by default. To share a mutable reference to an Int, wrap it in a class.

var a = 5 var b = a // b gets a copy of a b += 1 println(a) // 5 (unchanged) // Use a wrapper class to share a mutable reference class Box<T>(var value: T) val boxA = Box<Int>(10) val boxB = boxA // both point to the same Box boxB.value += 5 println(boxA.value) // 15

String Concatenation with Objects

When you concatenate an object with a String using +, Autolang automatically calls toString() on that object.

class User(val username: String) { fun toString(): String = "User: " + username } val u = User("bob") println(u + " is logged in") // Output: User: bob is logged in println("Welcome, " + u) // Output: Welcome, User: bob

Example

val name = "John" // String val age = 18 // Int val char: Int = 'A' // Character literal as Int (65) val money: Float = 4.5 // Float val email! = """autolang@gmail.com """ val child: Int? // Null value println("Hello everyone, my name is " + name + " and I'm " + age) println("Hello everyone, my name is ${name} and I'm ${age}") println("Now I have $money dollar and my email is $email") if (child == null) { println("I don't have any childs") } else { println("I have some childs") }