Part 27: Projects

Every other part of the course teaches one idea per lesson. This part does the opposite: each project is a complete small program that puts many ideas to work at once — a calculator that explains its errors, a word counter, a guessing game, a to-do list kept in a file, a command-line search tool. They are not meant to be read after Part 26. Each one is a checkpoint for an earlier part, and uses nothing the course has not taught by then, so you can stop after that part and build something real.

What you will learn

  • How the single ideas of the lessons combine into a program with a design: small functions with one job each, data described by types, and Main reading like a summary.
  • How to treat input as hostile: reading lines, parsing numbers, and telling the end of the input, a read error, a malformed number and an out-of-range one apart.
  • How to model every way a program can fail as an error type, and when to stop, pass a failure on, or skip it and carry on.
  • How to choose the right standard package for a job — collections, algorithms, time, randomness, entropy, files, JSON, regular expressions and the command line.
  • How to run interactive programs and command-line tools, and which projects need a keyboard, a sound card or Windows.

Which part unlocks which project

The arrows point from the part you need to have finished to the projects you can build after it:

flowchart LR
    p3["Part 3<br/>Control flow"] --> thanks["Thanks"]
    p3 --> fizz["FizzBuzz"]
    p4["Part 4<br/>Functions"] --> temp["Temperature"]
    p5["Part 5<br/>Sequences"] --> prime["Prime"]
    p9["Part 9<br/>Errors"] --> calc["Calculator"]
    p16["Part 16<br/>Numbers"] --> circle["Circle"]
    p16 --> quad["Quadratic"]
    p17["Part 17<br/>Collections"] --> words["Word count"]
    p17 --> inv["Inventory"]
    p18["Part 18<br/>Algorithms"] --> stats["Statistics"]
    p20["Part 20<br/>Utilities"] --> guess["Guess"]
    p20 --> age["Age"]
    p20 --> pass["Password"]
    p20 --> launch["Launch"]
    p21["Part 21<br/>Data formats"] --> notes["Notes"]
    p24["Part 24<br/>Platform"] --> melody["Melody"]
    p26["Part 26<br/>Systems"] --> grep["Grep"]
After partProjectWhat it practises
3 Control flowThanks, FizzBuzzLoops, match expressions, the order of an else if chain
4 FunctionsTemperatureSmall functions, recursion, default arguments
5 SequencesPrimeAn array of flags and the sieve of Eratosthenes
9 ErrorsCalculatorAn error variant, fail, ?, match and catch in one program
16 NumbersCircle, QuadraticReading and checking numbers, infinity, NaN and floating-point accuracy
17 CollectionsWord count, InventoryHash and tree maps, a vector of structs, two kinds of failure
18 AlgorithmsStatisticsSorting, folding and extremes, and the empty case
20 UtilitiesGuess, Age, Password, LaunchRandomness, entropy, calendar arithmetic, pauses and a game loop
21 Data formatsNotesJSON saved to a file atomically, and loaded back
24 PlatformMelodyCalling a Windows function directly, chosen while compiling
26 SystemsGrepOptions and help from CommandLine, a regular expression, files read line by line, an exit status

Circle and Quadratic are really about Part 14: Text — reading and parsing a line — but they also borrow IsFinite and the Math package from Part 16, so they unlock there.

Lessons

LessonWhat you will learn
27.1Thanksdraw RUX as an ASCII banner and thank everyone who helps build it
27.2FizzBuzzthe classic counting game
27.3Temperaturea table of Celsius and Fahrenheit temperatures
27.4Primeevery prime below 100, found with the sieve of Eratosthenes
27.5Calculatorevaluate expressions and report every way they can go wrong
27.6Circleread a radius, check it, and print the circle's measurements
27.7Quadraticsolve a quadratic equation, including linear and degenerate cases
27.8Word countcount how often each word appears
27.9Inventorykeep a stock list of items, with updates that can fail
27.10Statisticscount, extremes, mean, variance and median, including empty and single-value input
27.11Guessa number guessing game with seven valid guesses from 1 to 100
27.12Agean age in completed years, months and days, with month-end clamping
27.13Passworda 16-character password drawn from system entropy with rejection sampling
27.14Launcha mission checklist, a bounded countdown and a launch
27.15Noteskeep notes in a JSON file
27.16Melodyplay a tune through the Windows console speaker (Windows only)
27.17Grepsearch files for lines that match a regular expression, with command-line options

Before you start

Pick the project for the part you have just finished, rather than reading this part in order. Each project page lists exactly which lessons it leans on, links them where they are used, and ends with exercises that extend the program — those are the real work.

Each project is a package in the Examples repository's Projects/ folder:

cd Examples/Projects/FizzBuzz
rux run

Most projects print the same output on every run. A few are different:

ProjectWhat to expect
Circle, Quadratic, Guess, LaunchThey wait for you to type. Answer the prompt and press Enter, or pipe the input in
Guess, PasswordA different number or password on every run
NotesWrites a file in the package's Bin/ folder, and deletes it again
MelodyWindows only, and plays sound through the console speaker
GrepWith no arguments it searches its own source; give it arguments after -- to search your own files

After this part

This is the end of the course. From here, the best next step is a program of your own — take the project closest to what you want to build and change it until it is yours. The Rux Reference has the full rules behind every lesson, the API reference covers the standard packages, and the cheat sheet keeps the syntax on one page. When you want to share what you made, Part 22: Packages shows how to turn it into a package others can depend on.