Task guides

Each guide reaches one goal: the steps, the code, and what to watch out for. If you haven't built a program yet, start with Get started; for a longer walk through one program, the tutorial builds a quiz step by step.

Text and input

  • Read input from the user: read a line into a buffer with In.ReadLine, and handle the end of input, lines that don't fit, and numbers.
  • Format text: $"..." with alignment and number formats, written to stdout, into an arena string or into a StrBuilder.
  • Keep a string: copy a line or a scratch result into an arena that lives long enough, and collect such strings in a list or map.

Memory and collections

  • Choose a collection: List, Dict, RefList, StrDict or RefDict, keys for objects, and copying a collection into another arena.
  • Query data without allocating: Where, Select, Sum and query syntax over spans with lib/Seq.cs, tuples instead of anonymous types, and checking that a loop allocates nothing.
  • Pass structs by reference: allocate a struct in an arena, pass it with ref and in, return a ref, and keep the ref from outliving a list's buffer or an arena scope.
  • Catch arena mistakes: turn on Arena.DebugChecks, name your arenas, and see what the library stops the program for.

Targets

  • Build for WebAssembly: the toolchain, building and running a WASI module, and what differs from the native build.
  • Build for DOS: the toolchain, the emulators, memory, input from a file, and running a program on a real machine.
  • Draw on the VGA screen: graphics mode, colors, drawing a frame without flicker, and reading the keyboard under DOS.

Speed

  • Use SIMD: Vector128 and Vector256 without run-time CPU detection, the -m flags, and the ready-made kernels in lib/Kernels.cs.
  • Run a loop in parallel: Parallel.For over every processor, sharing a total with Interlocked, and one arena per thread.
  • Run a language model: a small Llama-style model, compiled into the program, telling stories on every target, DOS included.