Values & Variables
Names hold values. Kestrel splits "a name I'll change" from "a name I won't" at the syntax level — the compiler enforces the difference.
Variables
let binds a value once. var lets you change it.
let pi = 3.14159;
var counter = 0;
counter = counter + 1; // ok
// pi = 3.0; // compile error: pi is `let`
Type annotations are optional when the type is obvious from the right-hand side. Add one when you want to widen, narrow, or document:
let port: Int = 8080;
let name: String = "kestrel";
var attempts: Int = 0;
There's no uninitialized binding — every let and var must have a value at the point it's declared. If you genuinely don't have one yet, use Optional:
var nickname: Optional[String] = .None;
Literals
Integer literals support decimal, hex, binary, and octal:
let a = 42;
let b = 0xff; // 255
let c = 0b1010; // 10
let d = 0o755; // 493
Float literals require a .:
let pi = 3.14159;
let small = 0.001;
Booleans are true and false. Characters use single quotes; strings use double quotes:
let yes: Bool = true;
let letter: Char = 'A';
let greeting: String = "hello";
Common escape sequences in strings: \n, \t, \\, \", \0.
String Interpolation
Embed any expression inside "..." with \(...):
let name = "Morgana";
let level = 7;
let line = "\(name) reached level \(level)!";
Interpolated expressions can be any code that produces a value, including method calls:
let names = ["Merlin", "Morgana"];
let summary = "\(names.count) wizards: \(names.joined(", "))";
The syntax is \(...) — not ${...} or #{...}. Easy to mistype if you're coming from JavaScript or Ruby.
Operators
Standard arithmetic and comparison work the way you'd expect:
let sum = 3 + 4;
let product = 3 * 4;
let quotient = 10 / 3; // 3 — integer division truncates
let remainder = 10 % 3; // 1
let a = 7;
let b = 9;
let equal = (a == b);
let less = (a < b);
let hungry = true;
let tired = false;
let either = hungry or tired;
let both = hungry and tired;
Logical operators are keywords: and, or, not — not &&, ||, !. ! is bitwise NOT (flips bits).
Bitwise: &, |, ^, <<, >>, !. String concatenation uses +. For the full table with precedence and associativity, see Reference → Operators. To define operators on your own types, see Functions → Operator Overloading.