← Starting Henceforth
Episode 9
The three stacks
One stack is yours, one is the machine's — and the third belongs to bitcoin.
2:34 · Double Concerto in A minor · Allegro (RV 522 i)
Watch here · code in the app
Henceforth is the real terminal — one purchase ($9.99) for iPhone, iPad and Mac. Type the commands below into the app as you watch.
Code along
Tap to copy, then type it into Henceforth.
What you’ll learn
- ✓ >r takes the top of your stack and sets it down on the return stack — the machine's own pile. r> is the exact reverse: it brings the number home, and you never named it once.
- ✓ .s shows your stack, .rs the return stack, .ds the data stack — three stacks, three owners: yours, the machine's, and bitcoin's.
- ✓ Reaching into an empty pile is an error, not a mystery: r> on an empty return stack reports return stack underflow — each of the three stacks has its own floor.
Transcript
- one pile of numbers — that's all there is?
- no. henceforth runs three stacks. three owners.
- the first is yours — you've pushed numbers to it since episode two.
- .s shows your stack — 7, then 8.
- 8 landed last, so 8 sits on top.
- but where does the machine itself hold a number for later?
- i push 42 onto your stack first.
- then >r takes that top number — the 42 — straight off your stack...
- ...and sets it down on the return stack — the machine's own pile.
- watch your stack — back to two. 7 and 8. the 42 is gone.
- .rs shows the return stack — the machine's own.
- there's the 42, held for later. no variable needed.
- and to pull it back onto yours?
- r> is the exact reverse of >r.
- it takes the top of the return stack — the 42 — and sets it back on your stack.
- your stack now — 7, 8, 42. the 42 came home, sitting on top.
- moved to the machine's pile and back — and you never named it once.
- and the third stack?
- .ds prints the data stack. empty for now.
- not yours. not the machine's.
- this one is bitcoin's — the consensus stack a script runs on.
- next episode, we put the first values onto it.
- and reaching into an empty stack?
- the return stack's empty — the 42's already home.
- r> reaches for the top — and there's nothing to take. return stack underflow.
- one floor of three — each stack has its own.
- three stacks. one yours, one the machine's, one bitcoin's.
- you've worked two of them today.
- the third is the whole point of next time.
- henceforth.