Sn Tin

Chapter 1 of 8

Hello, Tin

A program is a file with a main. Strings interpolate, and everything is an expression.

examples/01-hello.tintin run examples/01-hello.tin
// The smallest Tin program. Run it with:  tin run examples/01-hello.tin

fn main() {
  let name = "Tin"
  print("Hello from {name}!")
  print("2 + 2 = {2 + 2}")
}
Hello from Tin!
2 + 2 = 4

let binds a value that never changes; var binds one that can. Types are inferred, so you write them where they help a reader, not where the compiler needs them. Anything inside {…} in a string is evaluated and printed.

if is an expression, so it can sit on the right of a let or inside a string. Functions with a single expression use =>.

examples/02-fizzbuzz.tintin run examples/02-fizzbuzz.tin
// Functions, ranges, and `if` as an expression.

fn fizzbuzz(n: int): string {
  if n % 15 == 0 { "FizzBuzz" }
  else if n % 3 == 0 { "Fizz" }
  else if n % 5 == 0 { "Buzz" }
  else { str(n) }
}

fn main() {
  for i in 1..16 {
    print(fizzbuzz(i))
  }
}
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz