Syntax Basics
Kite's syntax is designed to be clean, readable, and familiar to developers coming from modern programming languages. This page covers the fundamental building blocks: variables, types, operators, and literals.
Variables
The var Keyword
Variables are declared using the var keyword:
var name = "production"var count = 42var enabled = trueExplicit Type Annotations
Types can be explicitly specified:
var string name = "production"var number count = 42var boolean enabled = trueType Inference
When the type is omitted, Kite infers it from the initial value. The inferred type is fixed at declaration.
var name = "hello" // Inferred as stringvar count = 10 // Inferred as numbervar items = [1, 2, 3] // Inferred as number[]Types
Primitive Types
| Type | Description | Example |
|---|---|---|
string | UTF-8 text values with interpolation support | "hello", "Hello, ${name}!" |
number | 64-bit floating-point (integers and decimals) | 42, 3.14, -17, 1.5e10 |
boolean | Logical true/false values | true, false |
null | Explicit absence of a value | null |
any | Disables type checking (use sparingly) | var any x = "hello" |
Array Types
Arrays are declared with [] suffix:
var string[] names = ["alice", "bob"]var number[] scores = [95, 87, 92]var boolean[] flags = [true, false, true]Object Types
Objects use key-value syntax:
var config = { host: "localhost", port: 8080, ssl: true}Union Types
Union types allow multiple possible types:
var string | number id = "abc123"id = 42 // Also validFunction Types
Function type syntax:
// (param types) -> return typevar (number, number) -> number add = (a, b) -> a + b// No parametersvar () -> string greet = () -> "Hello"// No return valuevar (string) -> void log = (msg) -> print(msg)Operators
Arithmetic Operators
Kite supports standard arithmetic operations on numeric values. When mixing integers and decimals, integers are automatically promoted to floating-point. Division always returns a floating-point result, while modulo (%) returns the remainder after division.
var sum = 10 + 5 // 15var diff = 10 - 5 // 5var product = 10 * 5 // 50var quotient = 10 / 5 // 2.0 (always float)var remainder = 10 % 3 // 1Comparison Operators
Comparison operators return boolean values. Equality (==) and inequality (!=) work on all types including strings and booleans. Ordering comparisons (<, >,<=, >=) work on numbers and strings (lexicographic comparison).
a == b // Equal (works on all types)a != b // Not equala < b // Less thana > b // Greater thana <= b // Less than or equala >= b // Greater than or equal// String comparison is lexicographic"apple" < "banana" // true"abc" == "abc" // trueLogical Operators
Logical operators work with boolean values and use short-circuit evaluation:&& stops evaluating if the left side is false, and || stops if the left side is true. This is useful for conditional execution and providing default values.
a && b // AND: true only if both are truea || b // OR: true if either is true!a // NOT: inverts the boolean// Short-circuit evaluationenabled && runTask() // runTask() only called if enabled is truevalue || "default" // Returns value if truthy, otherwise "default"Assignment Operators
Assignment operators modify variables in place. Compound operators like += combine an operation with assignment. For arrays, += appends elements. The increment (++) and decrement (--) operators modify numeric variables by 1.
x = 10 // Assignx += 5 // Add and assign (x = x + 5)x -= 3 // Subtract and assignx *= 2 // Multiply and assignx /= 4 // Divide and assignx++ // Increment by 1x-- // Decrement by 1// Array append with +=var items = ["a", "b"]items += "c" // items is now ["a", "b", "c"]String Operators
Strings can be concatenated with +. Double-quoted strings support interpolation using ${expression} syntax for complex expressions or $variable for simple variables. Single-quoted strings are literal and do not process interpolation.
var greeting = "Hello" + " " + "World" // Concatenation// String interpolation (double quotes only)var name = "Alice"var message = "Hello, ${name}!" // "Hello, Alice!"var count = 3var items = "You have ${count} items" // "You have 3 items"// Expression interpolationvar total = "Sum: ${10 + 20}" // "Sum: 30"// Single quotes = no interpolationvar literal = '${name}' // "${name}" (literal text)Member Access
Access object properties with dot notation or bracket notation. Use bracket notation when the key is dynamic or contains special characters. Array elements are accessed by zero-based index.
object.property // Dot notation for known keysarray[0] // Array index (zero-based)object["key"] // Bracket notation (dynamic keys)// Examplesvar config = { host: "localhost", port: 8080 }var host = config.host // "localhost"var port = config["port"] // 8080var items = ["first", "second", "third"]var first = items[0] // "first"var last = items[items.length - 1] // "third"Range Operator
The range operator (..) creates a sequence of integers. The end value is exclusive, meaning 0..5 produces 0, 1, 2, 3, 4 (not including 5). Ranges are commonly used in for loops to iterate a specific number of times.
0..10 // Range from 0 to 9 (end exclusive)// Common for loop patternfor i in 0..5 { print(i) // Prints: 0, 1, 2, 3, 4}// Dynamic rangesvar count = 3for i in 0..count { print("Item ${i}")}Literals
String Literals
// Double quotes - with interpolationvar greeting = "Hello, ${name}!"// Single quotes - literal (no interpolation)var pattern = '^[a-z]+$'Number Literals
var integer = 42var negative = -17var decimal = 3.14159var scientific = 1.5e10Boolean Literals
var yes = truevar no = falseArray Literals
var empty = []var numbers = [1, 2, 3, 4, 5]var mixed = ["hello", 42, true]var nested = [[1, 2], [3, 4]]Object Literals
var empty = {}var config = { name: "server", port: 8080, tags: ["web", "api"]}Null Literal
var nothing = nullNext: Learn about Resources - the core building blocks for infrastructure.