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

  1. Hello, Avin: a first program, printing, and putting values into text.
  2. Values and types: val and var, numbers, text and truth values, and arithmetic.
  3. Functions: one-line functions, blocks, recursion, clauses, and default and named arguments.
  4. Choices and patterns: if as an expression, match, chained comparisons and loops.
  5. Data: your own types, taking them apart with patterns, Option, and failures as values with Result.
  6. Collections: vectors, maps and sets, map, filter and foldLeft, ranges, comprehensions, and a list that never ends.
  7. Closures and higher-order functions: functions as values, functions that make functions, and closures that remember.
  8. Classes and traits: objects with state, shared behaviour through traits, and inheritance.
  9. Literate programs: a program written as an essay, in a .lavin document.
  10. Putting it together: four complete programs, a word counter, a calculator, the eight queens and the Game of Life.

Pages

  • Hello, Avin — A first program, printing, and putting values into text.
  • Values and types — `val` and `var`, numbers, text and truth values, conversions, and arithmetic.
  • Functions — One-line functions, blocks, recursion, clauses, and default and named arguments.
  • Choices and patterns — `if` as an expression, `match` and its patterns, chained comparisons, and loops.
  • Data — Your own types with `data`, taking them apart with patterns, `Option`, and failures as values with `Result`.
  • Collections — Vectors, maps and sets, `map`, `filter` and `foldLeft`, ranges, comprehensions, and a list that never ends.
  • Closures and higher-order functions — Functions as values, functions that take and make functions, and closures that remember.
  • Classes and traits — Objects with state, shared behaviour through traits, inheritance, and implementations for types you did not write.
  • Literate programs — A program written as an essay, in a `.lavin` document whose prose is Markdown and whose code is the lines indented four columns.
  • Putting it together — Four complete programs, a word counter, a calculator, the eight queens and the Game of Life, each using what the book has shown.

Search

Esc
↑↓ to navigate ↵ to open Esc to close