Nim Demo Examples
How to use: click View to open a file in the code viewer, read its comments, download it to your machine, and compile it with the Nim toolchain. Most demos need only nim c -r <file>; the threads demo needs the default --mm:orc, and the build-modes demo is worth running three times with different defines.
nim c -r 01_hello.nim # compile and run (debug build)
nim c -r -d:release 19_buildmodes.nim # same source, optimized build
nim c -r 15_threads.nim # threads are on by default in Nim 2.x
nim c -r 16_interop.nim # links against libc (math.h, stdlib.h)
Foundations
Values, control flow and routines — the whole of PHASE 1 and PHASE 2.
| # | Description | Link |
|---|---|---|
| 1 | Hello, World and echo | View |
| 2 | Values, Variables and Types | View |
| 3 | Selection and Iteration | View |
| 4 | Procedures and First-Class Functions | View |
Data Modelling
Objects, variants, containers and text — PHASE 3, where data structures become the design.
| # | Description | Link |
|---|---|---|
| 5 | Objects and Dynamic Dispatch | View |
| 6 | Enums, Sets and Variant Objects | View |
| 7 | Arrays, Sequences, Sets and Tables | View |
| 8 | Strings, Characters and Formatting | View |
Abstraction & Reuse
Generics, modules, iterators and metaprogramming — PHASE 4, the machinery that lets one program serve many cases.
| # | Description | Link |
|---|---|---|
| 9 | Generics and Type Classes | View |
| 10 | Modules and Imports | View |
| 11 | Inline and Closure Iterators | View |
| 12 | Templates and Macros | View |
Safety & Performance
Errors, memory, concurrency and the C boundary — PHASE 5, where a correct program becomes a fast, reliable one.
| # | Description | Link |
|---|---|---|
| 13 | Exceptions, defer and Option | View |
| 14 | Value vs Reference Semantics | View |
| 15 | Threads, Channels and Async | View |
| 16 | C Interop and Static Libraries | View |
Engineering Practice
Tests, file I/O, build modes and project configuration — PHASE 6, how the work ships.
| # | Description | Link |
|---|---|---|
| 17 | Unit Tests with std/unittest | View |
| 18 | Files, Paths and Command-Line Options | View |
| 19 | Build Modes and Runtime Checks | View |
| 20 | Project Configuration (config.nims) | View |