Skip to content

boringcollege/zig-by-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig by Example

Zig 0.16 License: CC BY 4.0

A hands-on introduction to Zig via annotated examples. Zig is a general-purpose, compiled systems language focused on robustness, optimality, and simplicity — no hidden control flow, no hidden allocations, no preprocessor.

Written by Dariush Abbasi for Boring College


Layout

  • content/NN-name.md — the annotated chapter
  • examples/NN-name.zig — the runnable source

Every code block in content/ mirrors the matching examples/*.zig file and has been compiled against the target Zig version.

Index

  1. Hello, World
  2. Values
  3. Variables
  4. Integers
  5. Floats
  6. Strings
  7. Arrays
  8. Slices
  9. Vectors
  10. Structs
  11. Enums
  12. Unions
  13. Functions
  14. Blocks and Statements
  15. If / Else
  16. Switch
  17. While Loops
  18. For Loops
  19. Defer
  20. Errors
  21. Optionals
  22. Pointers
  23. Multi-Pointers
  24. Slices (Pointers)
  25. Comptime
  26. Generics
  27. Memory Allocation
  28. ArrayList
  29. HashMap
  30. Linked List
  31. Testing
  32. Formatting and Print
  33. Io Interfacenew in 0.16
  34. Writer & Readernew
  35. File I/O
  36. Threading & Concurrencynew
  37. Processes
  38. Networking & HTTPnew
  39. JSON
  40. Random Numbers
  41. Sorting
  42. Math
  43. Build System
  44. C Interop

Running the examples

Install Zig 0.16.0 — brew install zig on macOS, or grab a tarball from ziglang.org/download. Then:

$ zig run examples/01-hello-world.zig
Hello, World!

A few examples need extra flags:

$ zig test examples/31-testing.zig            # tests
$ zig run  examples/44-c-interop.zig -lc      # link libc

Further Reading


Zig by Example is inspired by Go by Example by Mark McGranaghan. Examples target Zig 0.16.

Contributions welcome — see CONTRIBUTING.md.

Packages

 
 
 

Contributors