Grav v1.14.0

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

#ChapterYou will learn
1Getting startedinstalling, your first program, building, reading errors, the grav tools
2Values, variables and typeslet and const, numbers, booleans, conversions, operators
3Strings and textliterals, raw and multi-line strings, interpolation, formatting, characters, Str
4Control flowif, loops, ranges, break and labels, switch/match, defer
5Functionsparameters, defaults and named arguments, overloading, variadics, recursion
6Lambdas and closuresfunction types, closures, map/filter/reduce

Part 2: Organising data

#ChapterYou will learn
7Arrays and collectionsfixed arrays, Array, maps, sets, collection literals, choosing a collection
8Structs, enums and tuplesvalue types, enums, data enums and pattern matching, tuples, any
9Null safetynull, ??, ?., nullable types T?, narrowing, Option

Part 3: Objects

#ChapterYou will learn
10Classesfields, constructors, methods, access control, statics, destructors
11Inheritance and interfacessubclasses, abstract classes, interfaces, traits, is/as
12Operators and overloadingmethod overloading, operator methods, indexing
13Genericsgeneric classes and functions, bounds, inference

Part 4: Writing real programs

#ChapterYou will learn
14Errors and exceptionsthrow/try/catch/finally, Result, panics and recovery
15Memoryreference counting, cycles and weak, free and defer
16Modules and packagesimport, namespaces, use, projects, packages
17C interopinline C, pointers, sizeof, macros
18Concurrencyasync/await, the worker pool, mutexes, channels, threads
19Testingtest blocks, assertions, grav test
20How Grav compilesthe 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