Learning Grav
This guide teaches Grav from the ground up, one idea at a time. Each chapter explains the why along with the how, shows small programs with their exact output, and ends with a summary and exercises. The early chapters assume no experience with statically typed languages; later ones build on earlier ones, so reading in order works best.
Every complete program in these pages is compiled and run by the test suite, so what you read is what the compiler does.
#Part 1: The basics
| # | Chapter | You will learn |
| 1 | Getting started | installing, your first program, building, reading errors, the grav tools |
| 2 | Values, variables and types | let and const, numbers, booleans, conversions, operators |
| 3 | Strings and text | literals, raw and multi-line strings, interpolation, formatting, characters, Str |
| 4 | Control flow | if, loops, ranges, break and labels, switch/match, defer |
| 5 | Functions | parameters, defaults and named arguments, overloading, variadics, recursion |
| 6 | Lambdas and closures | function types, closures, map/filter/reduce |
#Part 2: Organising data
| # | Chapter | You will learn |
| 7 | Arrays and collections | fixed arrays, Array, maps, sets, collection literals, choosing a collection |
| 8 | Structs, enums and tuples | value types, enums, data enums and pattern matching, tuples, any |
| 9 | Null safety | null, ??, ?., nullable types T?, narrowing, Option |
#Part 3: Objects
| # | Chapter | You will learn |
| 10 | Classes | fields, constructors, methods, access control, statics, destructors |
| 11 | Inheritance and interfaces | subclasses, abstract classes, interfaces, traits, is/as |
| 12 | Operators and overloading | method overloading, operator methods, indexing |
| 13 | Generics | generic classes and functions, bounds, inference |
#Part 4: Writing real programs
| # | Chapter | You will learn |
| 14 | Errors and exceptions | throw/try/catch/finally, Result, panics and recovery |
| 15 | Memory | reference counting, cycles and weak, free and defer |
| 16 | Modules and packages | import, namespaces, use, projects, packages |
| 17 | C interop | inline C, pointers, sizeof, macros |
| 18 | Concurrency | async/await, the worker pool, mutexes, channels, threads |
| 19 | Testing | test blocks, assertions, grav test |
| 20 | How Grav compiles | the pipeline, the generated C, performance |
#After the guide
- The language reference has the precise rules: keywords, types, operators, statements, every built-in function, the command line, and run-time errors.
- The standard library reference has a page for every module.
examples/ has longer programs, one per topic, plus a few small applications.
Edit this page on GitHub