# Your first program

> Write, run, edit, and inspect a complete Alice program.

Canonical: https://alice-lang.org/documentation/learn/first-program/

[Documentation index](https://alice-lang.org/documentation/llms.txt) · [Complete book](https://alice-lang.org/llms-full.txt)

## Say hello

This is a complete program. Use **Edit & run** to change `Alice` to your name, then press **Run** in the editor.

```alice
def greet(name : String) : String
  "Hello, #{name}!"
end
puts greet("Alice")
```

Expected output:

```text
Hello, Alice!
```

[Edit and run in the Alice playground](https://playground.alice-lang.org/#code=u.ZGVmIGdyZWV0KG5hbWUgOiBTdHJpbmcpIDogU3RyaW5nCiAgIkhlbGxvLCAje25hbWV9ISIKZW5kCnB1dHMgZ3JlZXQoIkFsaWNlIik)

`def` starts a method. `name : String` gives its parameter a type, and the `: String` after the parentheses gives its return type. The final expression becomes the result: an explicit `return` is unnecessary here. `end` closes the method.

`"Hello, #{name}!"` inserts the value of `name` into a string. `puts` prints its argument followed by a newline. The final top-level statement calls `greet` and prints its result.

## Run it locally

Save the source above in `hello.al`, then run:

```sh
alice run hello.al
```

A single file does not need a manifest. Alice compiles the program before running it. You will see:

```text
Hello, Alice!
```

Try changing the call to `greet(42)`. The parameter requires a `String`, so the compiler rejects the call. Correct it to `greet("42")` to pass a string.

## Check or inspect a program

```sh
alice check hello.al
alice emit hello.al
alice build hello.al
```

`check` reports compilation errors without running the program. `emit` shows the lowered C# used to produce .NET IL. `build` creates the assembly without executing it. In the playground, the compiler-stage tabs let you inspect intermediate forms alongside the output.

The generated C# is an inspection tool. Keep `.al` as your source; editing emitted output does not change the Alice program.

## Exercise

Add a second method, `farewell(name : String) : String`, that returns `"Goodbye, #{name}!"`. Print both greetings. Each method should return a string; the caller decides whether to print it. This separation makes the methods useful in tests and applications.

Next, take the [language tour](https://alice-lang.org/documentation/learn/tour.md).

## Continue reading

- Previous: [Install Alice](https://alice-lang.org/documentation/learn/installation.md)
- Next: [A tour of Alice](https://alice-lang.org/documentation/learn/tour.md)
