The Avin Book
Learn Avin one idea at a time, through small programs that grow into complete ones.
This book teaches Avin by example. Each chapter starts with a small, complete program, adds one idea at a time, and ends with a few exercises to try on your own. Every program in it is a whole program you can run, and the output shown beside it is what it prints: the book’s programs are built and run with the compiler’s own tests, so what you read here is what Avin does.
The specification is where each feature is defined in full, and the system library is where its modules are documented. The book links to both when an idea first appears, for when you want the whole story.
Before you start, install Avin. To run a program from the book, save it in a
file, say hello.avin, and run it:
avin run hello.avin
Chapters
- Hello, Avin: a first program, printing, and putting values into text.
- Values and types:
valandvar, numbers, text and truth values, and arithmetic. - Functions: one-line functions, blocks, recursion, clauses, and default and named arguments.
- Choices and patterns:
ifas an expression,match, chained comparisons and loops. - Data: your own types, taking them apart with patterns,
Option, and failures as values withResult. - Collections: vectors, maps and sets,
map,filterandfoldLeft, ranges, comprehensions, and a list that never ends. - Closures and higher-order functions: functions as values, functions that make functions, and closures that remember.
- Classes and traits: objects with state, shared behaviour through traits, and inheritance.
- Literate programs: a program written as an essay, in a
.lavindocument. - Putting it together: four complete programs, a word counter, a calculator, the eight queens and the Game of Life.