Files
rexlang/docs/01-first-steps.md
T
Your NameandClaude Sonnet 5.5 eaf9567a36 Dino compiler: language, formatter, language server, docs, editor support
Compiler in Rust (lexer, parser, checker, C codegen), maps, chars,
dino fmt, dino lsp (diagnostics, formatting, outline, definition,
hover, completion, signature help), docs, examples, VS Code/Vim files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 23:46:12 +01:00

101 lines
2.7 KiB
Markdown

# 1. First steps
## Running a program
Save this as `hello.dino`:
```dino
func main() {
print("Hello, Dino!")
}
```
```text
Hello, Dino!
```
Every program starts at `func main()`. Run it from the project folder:
```text
cargo run -q -- run hello.dino
```
The compiler turns your Dino code into C and builds it with your C compiler (`cc`, so you
need gcc or clang installed). If you build the `dino` binary once, the commands are:
| Command | What it does |
|---------|--------------|
| `dino run file.dino [args...]` | Compile and run. Extra words are given to the program (`os.args`). |
| `dino build file.dino -o out` | Make an executable you can keep. |
| `dino check file.dino` | Look for errors without building. |
| `dino emit-c file.dino` | Print the generated C. |
| `dino fmt file-or-folder...` | Tidy the code in place (`--check` only reports). |
## print
`print` takes any number of values, separates them with spaces, and ends the line.
It can print numbers, strings, lists, maps, structs, enums and more.
```dino
func main() {
print("score:", 42, true)
print([1, 2, 3])
print(1.5 + 1.5)
}
```
```text
score: 42 true
[1, 2, 3]
3.0
```
Notice that a float always shows a `.0` so you can tell `3.0` from `3`.
## Comments
```dino
// a comment runs to the end of the line
func main() {
print("hi") // so does this
}
```
```text
hi
```
## Reading the error messages
Dino tries hard to explain mistakes. For example, forgetting that `int` and `float`
don't mix:
```text
error: can't use `int` and `float` together (convert with `float(x)`)
```
When a message offers a hint, try it. If it doesn't make sense, that is a bug in the
message and worth fixing.
## Your editor
`editors/` has colours, live error underlines and format-on-save for VS Code, Neovim, Vim and
Helix (any editor that can run a language server works). See `editors/README.md`. It is the
compiler itself doing the checking, so you see the same messages as in the terminal. The
server is started with `dino lsp`.
## Formatting your code
`dino fmt` rewrites your files in one standard style, so you never argue about spaces:
```text
dino fmt hello.dino # one file
dino fmt src/ # every .dino file in a folder
dino fmt --check src/ # change nothing; exit code 1 if something is untidy
```
It uses 4-space indents, one space around operators, `a: int` colons, `Point{x: 1}` literals,
and at most one blank line in a row. It keeps your comments and **never moves a line break**,
so how you split things across lines is up to you. Trailing `//` comments on neighbouring
lines are lined up. Before saving, it checks that the code means exactly the same thing, and
it refuses files that don't parse.
Next: [Values and types](02-values-and-types.md)