Basics
basics/main.xo
const GREETING = "hello"
fn greet(name: Str) -> Str {
"${GREETING}, ${name}"
}
fn sign(n: Int) -> Str {
if n < 0 { "negative" } else if n == 0 { "zero" } else { "positive" }
}
fn main(os: Os) {
let who = "Ada"
var count = 0
for i in 0..3 {
count += i
}
os.stdio.println(greet(who))
os.stdio.println("count = ${count}, sign = ${sign(count - 5)}")
}Output:
hello, Ada
count = 3, sign = negative
letbinds a value that never changes;varbinds one that can. Mutating aletis a compile error, and so is a binding you never use.- The last expression of a block is its value, so
greetneeds noreturn.ifis an expression too. "${expr}"interpolates any value that implementsDisplay.mainreceives the operating system asos. Printing goes throughos.stdio; step 8 explains why.0..3is a half open range (0, 1, 2);0..=3includes 3.