Learning Nifla — a tutorial in eleven lessons
Nifla is a small programming language that speaks in plain words. It was made to be read: if you can read a little JavaScript, you can read Nifla, and most of what surprises people is how little there is to memorize.
This book is a course, not a reference. It assumes you are intelligent and that you have never programmed before, and it teaches programming itself — what a program is, what keeping a value means, why loops exist — by building real programs in Nifla, one small step at a time. Nothing in it is decorative: every idea arrives because the next program needs it, and you will run something real within the first minutes of every lesson.
Here is the promise this course makes, plainly. You will write Nifla the way you write JavaScript: type a program, run it, see what it says — no ceremony, no waiting. And what you write will run with Swift's strength: checked before it runs, compiled to stand on its own, honest about kinds and about nothing. And by the end of the course you will have touched the very same language — not a teaching dialect, not a simplified subset for students — that an operating system, Cardnull OS 2, is written in. The words of your first say "Hello, world" are words that boot a computer.
Three habits run through the whole course:
- One new idea at a time. Each step adds exactly one
thing. If a program below ever looks like two new ideas at once, the book has failed, not you — re-read the step before it.
- Your turn, constantly. After nearly every idea there
is a tiny exercise. Try it before you peek: the worked answer stands right after it, set apart, and struggling for two minutes teaches more than reading for twenty.
- One program, growing. A single project — a *giving
ledger*, a little book that keeps a record of gifts — grows quietly at the end of most lessons, one piece at a time. By the last lesson you will have built it entire, and you will recognize every piece, because you built each one when it was small.
The language's other book, PRIMER.md, is the reference shelf: every word and every tool, one at a time. When a lesson here leaves you wondering "what else can this word do?", the Primer is where to look it up. This tutorial teaches the path; the Primer keeps the whole map.
Three programs carry the language:
nifla program.nifla— checks a program, then runs it.niflac program.nifla— checks it, then compiles it
into a program that stands on its own. With --bare it compiles a smaller, sterner subset of the language into a binary that boots on bare metal, with no operating system underneath; with --bare --guest --feather it makes a feather — a guest program with its card laid on it, the form a host's door receives (Lesson 9).
feathercheck program.feather— reads a feather and
answers, in plain words, whether its card is true.
In this repository, one command builds all three:
./build.sh
That leaves ./nifla, ./niflac, and ./feathercheck standing in the folder, ready to use.
Every example in this book is real. A standing proof (run-tutorial.sh) takes each program out of the book and runs it — interpreted, and compiled where it can be — and the proof fails if any program's output drifts from what the book says. The proof runs every example with the same two program arguments, Ada and Byron (Lesson 8 shows what program arguments are), and it runs each example in a fresh, empty folder, so the lessons that write files (Lesson 6 onward) always start in an empty room — on your own machine, those files will still be there the second time you run the program, and that difference is itself one of the lessons.
A word about errors, before we start: when a Nifla program goes wrong, the language answers in plain words, with the line number, and tries to say what would fix it. And before a program runs at all, a checker reads it and refuses — in the same plain words — programs it can prove will go wrong in certain ways. You will meet the checker properly in Lesson 5. It is a kind character in this story: it would rather stop you at the door, with an explanation, than let you fall down the stairs.
---
- Lesson 1 — Saying and keepingRead it, run it, then try your turn — every example runs right on the page.
- Lesson 2 — Deciding and repeatingRead it, run it, then try your turn — every example runs right on the page.
- Lesson 3 — Keeping many thingsRead it, run it, then try your turn — every example runs right on the page.
- Lesson 4 — Making your own toolsRead it, run it, then try your turn — every example runs right on the page.
- Lesson 5 — Kinds and nothingRead it, run it, then try your turn — every example runs right on the page.
- Lesson 6 — Papers that stayRead it, run it, then try your turn — every example runs right on the page.
- Lesson 7 — When things go wrongRead it, run it, then try your turn — every example runs right on the page.
- Lesson 8 — Standing on its ownRead it, run it, then try your turn — every example runs right on the page.
- Lesson 9 — Your first featherRead it, run it, then try your turn — every example runs right on the page.
- Lesson 10 — A first look downstairsRead it, run it, then try your turn — every example runs right on the page.
- Lesson 11 — Capstone: the giving ledger, wholeRead it, run it, then try your turn — every example runs right on the page.
Try Nifla
Or skip ahead and write your own program in the Try Nifla playground — the whole language, in the browser, with the checker watching over it.