<!-- Hello, Tin · Tin · https://tin.ad/docs/learn/hello/ · generated from the built page -->

[Learn](https://tin.ad/docs/learn/) · The language · 1 of 34

# Hello, Tin

**Goal.** Run a Tin program, put values into text, and read the compiler's error messages.

## Your first program

A Tin program is a file that ends in `.tin`. It starts running at a function called
`main`. Here is the smallest useful one:

*hello.tin · tin run hello.tin*

```tin
fn main() {
  print("Hello, Tin!")
}
```

<!-- output -->
```text
Hello, Tin!
```

`fn` declares a function. The body goes between `{` and `}`.
`print` writes a line of text. The box under the code is what the program printed.

## Running it

You have two options:

- **In the browser.** Open the [playground](https://tin.ad/docs/play/), paste the code and press Run.
Nothing to install. The compiler runs in your browser.

- **On your computer.** On macOS or Linux with Node 24 or newer, install the `tin` command
([Install](https://tin.ad/docs/install/) has the details) and run the file:

```sh
curl -fsSL https://tin.ad/install.sh | bash
tin run hello.tin
```

 `tin run` compiles the file to WebAssembly and runs it. You never see the compile step:
on a small file it takes a few milliseconds.

## Text with values in it

Put any expression inside `{ }` in a string, and its value is written there. This is called
interpolation. `let` gives a value a name.

*greet.tin · tin run greet.tin*

```tin
// A line starting with // is a comment. Tin ignores it.
fn main() {
  let name = "Ada"
  print("Hello, {name}!")              // {name} is replaced by its value
  print("{name} has {name.len} letters")
  print("2 + 3 = {2 + 3}")             // any expression works inside { }
}
```

<!-- output -->
```text
Hello, Ada!
Ada has 3 letters
2 + 3 = 5
```

When a function is a single expression, you can write it on one line with `=>`:

*short.tin · tin run short.tin*

```tin
fn main() => print("A one-line program.")
```

<!-- output -->
```text
A one-line program.
```

## Reading an error

You will make mistakes, so it is worth learning to read the compiler's answer early. Here the name is
misspelled:

*typo.tin · tin check typo.tin*

```tin
fn main() {
  let greeting = "Hello"
  print(greting)
}
```

<!-- compiler output -->
```text
error: unknown name 'greting'
 --> typo.tin:3:9
  |
3 |   print(greting)
  |         ^^^^^^^
  = note: did you mean 'greeting'?
  = fix: use greeting
```

Every error has the same shape: what went wrong, the file, line and column (`typo.tin:3:9`), the
line itself with the problem underlined, and often a `note` that says what to change. For some
errors the compiler knows the exact edit (the `fix` line), and `tin fix typo.tin` applies
it for you: here it would write `greeting`.

Two mistakes people often make when they come from other languages:

*toplevel.tin · tin check toplevel.tin*

```tin
print("Hello, Tin!")
```

<!-- compiler output -->
```text
error: expected a declaration (fn, tool fn, type, agent, let, test), found 'print'
 --> toplevel.tin:1:1
  |
1 | print("Hello, Tin!")
  | ^^^^^
```

  Code runs only inside functions. The top of a file is for declarations.

*mix.tin · tin check mix.tin*

```tin
fn main() {
  let year = 2026
  print("It is " + year)
}
```

<!-- compiler output -->
```text
error: '+' joins two strings, found string and int
 --> mix.tin:3:9
  |
3 |   print("It is " + year)
  |         ^^^^^^^^^^^^^^^
  = note: put the value in the string instead: "total: {n}"
  = fix: interpolate it
```

  Tin never turns a number into text by itself. Write "It is {year}" instead.

Tin checks the whole program before it runs any of it. If `tin run` prints an error,
nothing ran, not even the lines above the mistake.

## Trying one line at a time

`tin repl` lets you type an expression and see its value right away, which is handy for
checking how something behaves. Type `1 + 2 * 3` and it answers `7`. Leave with Ctrl-D.

## Tasks

### Task 1: Introduce yourself

Write a program that stores your name and your city with `let`, then prints two lines:
`My name is …` and `I live in …`.

Your answer   Checking needs JavaScript; the solution below works without it.

**Solution

*task-1.solution.tin · tin run task-1.solution.tin*

```tin
fn main() {
  let name = "Grace"
  let city = "Arlington"
  print("My name is {name}.")
  print("I live in {city}.")
}
```

<!-- output -->
```text
My name is Grace.
I live in Arlington.
```

### Task 2: Fix it from the error

This program doesn't compile. Read the error, then fix the program so it prints `Hello from Tin!`.

*task-2.tin · tin check task-2.tin*

```tin
fn main() {
  let first = "Tin"
  print("Hello from {frist}!")
}
```

<!-- compiler output -->
```text
error: unknown name 'frist'
 --> task-2.tin:3:22
  |
3 |   print("Hello from {frist}!")
  |                      ^^^^^
  = note: did you mean 'first'?
  = fix: use first
```

Your answer   Checking needs JavaScript; the solution below works without it.

**Solution

*task-2.solution.tin · tin run task-2.solution.tin*

```tin
fn main() {
  let first = "Tin"
  print("Hello from {first}!")
}
```

<!-- output -->
```text
Hello from Tin!
```

### Task 3: Let Tin do the arithmetic

Print `Minutes in a week: …` with the number filled in. Don't work it out yourself: put the
calculation inside the string.

Your answer   Checking needs JavaScript; the solution below works without it.

**Solution

*task-3.solution.tin · tin run task-3.solution.tin*

```tin
fn main() {
  print("Minutes in a week: {7 * 24 * 60}")
}
```

<!-- output -->
```text
Minutes in a week: 10080
```

## Recap

- A program starts at `fn main()`; `print` writes a line.
- `"{x}"` puts any expression into a string.
- Every error says where, what, and usually how to fix it.

In the reference: [Programs](https://tin.ad/docs/ref/language/#programs) · [Strings](https://tin.ad/docs/ref/language/#strings) · [The tin command](https://tin.ad/docs/ref/cli/)
