← Starting Henceforth

Episode 5

Moving numbers

The shuffle words change where numbers sit — never what they are.

1:35 · Brandenburg No. 3 · Allegro (BWV 1048 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

  • The stack only ever hands you its top — so to use a number twice, in a new order, or from underneath, you reach for a mover: dup, swap, over, rot, drop.
  • Movers change where numbers sit, never what they are. swap flips the top two, so 10 4 swap - leaves 4 - 10 = -6 — same numbers, new order.
  • A mover still needs operands — swap on a one-item stack hits the floor (underflow). Bitcoin Script has the same move, OP_DUP, which you'll wield in episode ten.
Transcript
  • last time — you copied the top.
  • that was dup. it made square.
  • dup's got a family — words that just move numbers.
  • because the stack only ever hands you the top.
  • dup — copy the top. you've met this one.
  • what if they're backwards?
  • i want 4 minus 10 — but 4's on top.
  • swap — flip the top two.
  • minus six. same numbers, new order.
  • and the one underneath?
  • over — copy the second one up top.
  • buried deeper?
  • rot — bring the bottom one up.
  • and when you don't need it?
  • drop — throw the top away. pretty simple, huh?
  • but they still need numbers to move.
  • give swap one — it hits the floor.
  • movers need a stocked stack.
  • watch — none of them did math.
  • they only move numbers. never change what they are.
  • bitcoin has this same move — op_dup.
  • you'll wield it in episode ten.
  • henceforth.