# The interactive REPL

> Explore values and types, edit multiline inputs, search history, and use help and package modes.

Canonical: https://alice-lang.org/documentation/tools/repl/

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

## Start a session

```sh
alice
# or
alice repl
```

An expression prints its value and type. `ans` refers to the previous result. Definitions remain available during the session.

```text
alice> 2 + 3
5 :: Int32
```

Piped stdin is evaluated noninteractively. Inside a project, the REPL compiles against that project's references.

## Multiline input

Open `def`, `class`, `do`, and other blocks continue with a `⋮` prompt until closed. Input is highlighted, matching brackets are marked, continuation lines indent automatically, and `end`/`else`/`when` dedent.

## Session commands

| Command              | Meaning                         |
| -------------------- | ------------------------------- |
| `:help`, `:quit`     | Show commands or exit           |
| `:reset`             | Clear the session               |
| `:load file.al`      | Load a file                     |
| `:save file.al`      | Save session input              |
| `:type expression`   | Inspect a static type           |
| `:emit code`         | Inspect lowered C#              |
| `:time expression`   | Measure an evaluation           |
| `:history`, `:clear` | Show inputs or clear the screen |

## Help, shell, and package modes

At an empty prompt, `?` enters help mode. Try `?puts`, `?String`, `?Math.Sqrt`, or `?def`. `;` enters shell mode and `]` enters package mode. Package commands include `add`, `remove`, `list`, `search`, and `install`. Backspace on an empty mode prompt returns to `alice>`.

## Editing and history

| Key                              | Behavior                                        |
| -------------------------------- | ----------------------------------------------- |
| `↑` / `↓`                        | History; typed text filters by prefix           |
| `→`, `End`, `Ctrl E` at line end | Accept a grey history hint                      |
| `Ctrl R`                         | Reverse search; repeat for older matches        |
| `Enter` / `Esc` during search    | Accept / cancel                                 |
| `Tab`                            | Complete names, keywords, members, and commands |
| `Alt/Ctrl ←/→`, `Alt B/F`        | Word motion                                     |
| `Ctrl W/K/U`, `Alt D`            | Delete word/line portions                       |
| `Ctrl C`, `Ctrl L`, `Ctrl D`     | Clear line, clear screen, exit                  |

History is stored in `~/.alice_history`. Avoid entering secrets you do not want retained in history or saved session files.

## Evaluation model

Each input is compiled with earlier inputs. Earlier statements are re-executed with their console output muted so values retain static types. Their other effects can repeat: a file write or network request is not undone simply because its output is hidden.

Use `:reset` before repeating effectful experiments, and use a normal script or test for a workflow where execution must happen exactly once. Timing from the REPL can include compilation and session work; use a controlled benchmark for throughput measurements.

## Continue reading

- Previous: [Workspaces and package graphs](https://alice-lang.org/documentation/tools/workspaces.md)
- Next: [Toolchains and updates](https://alice-lang.org/documentation/tools/toolchains.md)
