Skip to main content
Documentation

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   = 42
var enabled = true

Explicit Type Annotations

Types can be explicitly specified:

var string name     = "production"
var number count    = 42
var boolean enabled = true

Type 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 string
var count = 10        // Inferred as number
var items = [1, 2, 3] // Inferred as number[]

Types

Primitive Types

TypeDescriptionExample
stringUTF-8 text values with interpolation support"hello", "Hello, ${name}!"
number64-bit floating-point (integers and decimals)42, 3.14, -17, 1.5e10
booleanLogical true/false valuestrue, false
nullExplicit absence of a valuenull
anyDisables 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 valid

Function Types

Function type syntax:

// (param types) -> return type
var (number, number) -> number add = (a, b) -> a + b

// No parameters
var () -> string greet             = () -> "Hello"

// No return value
var (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  // 15
var diff      = 10 - 5  // 5
var product   = 10 * 5  // 50
var quotient  = 10 / 5  // 2.0 (always float)
var remainder = 10 % 3  // 1

Comparison 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 equal
a < b  // Less than
a > b  // Greater than
a <= b  // Less than or equal
a >= b  // Greater than or equal

// String comparison is lexicographic
"apple" < "banana"  // true
"abc" == "abc"  // true

Logical 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 true
a || b  // OR: true if either is true
!a  // NOT: inverts the boolean

// Short-circuit evaluation
enabled && runTask()  // runTask() only called if enabled is true
value || "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  // Assign
x        += 5  // Add and assign (x = x + 5)
x        -= 3  // Subtract and assign
x        *= 2  // Multiply and assign
x        /= 4  // Divide and assign
x++  // Increment by 1
x--  // 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    = 3
var items    = "You have ${count} items"  // "You have 3 items"

// Expression interpolation
var total    = "Sum: ${10 + 20}"  // "Sum: 30"

// Single quotes = no interpolation
var 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 keys
array[0]  // Array index (zero-based)
object["key"]  // Bracket notation (dynamic keys)

// Examples
var config = { host: "localhost", port: 8080 }
var host   = config.host  // "localhost"
var port   = config["port"]  // 8080

var 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 pattern
for i in 0..5 {
    print(i)  // Prints: 0, 1, 2, 3, 4
}

// Dynamic ranges
var count = 3
for i in 0..count {
    print("Item ${i}")
}

Literals

String Literals

// Double quotes - with interpolation
var greeting = "Hello, ${name}!"

// Single quotes - literal (no interpolation)
var pattern  = '^[a-z]+$'

Number Literals

var integer    = 42
var negative   = -17
var decimal    = 3.14159
var scientific = 1.5e10

Boolean Literals

var yes = true
var no  = false

Array 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 = null

Next: Learn about Resources - the core building blocks for infrastructure.