Lessons

Forth · Introductory

Forth · Introductory. Ten lessons. Open-book quizzes. Lesson 1 free.

10 lessons · The Host · Lesson 1 free

Pass all ten lessons for the certificate. Sample · Claim

  1. Hello, Forth: the data stack and words

    Lesson 1 · On the house

    Hello, Forth: the data stack and words

    Run Forth with gforth, push numbers onto the data stack, print with . and read stack effects with .s.

  2. Arithmetic in postfix

    Lesson 2

    Arithmetic in postfix

    Write maths in reverse Polish notation with + - * / mod /mod, negate, abs, min and max, and see integer division.

  3. Stack shuffling: dup, drop, swap, over, rot

    Lesson 3

    Stack shuffling: dup, drop, swap, over, rot

    Rearrange the data stack with dup, drop, swap, over, rot, nip, tuck and 2dup, and read each word's stack effect.

  4. Defining words with : and ;

    Lesson 4

    Defining words with : and ;

    Extend Forth with colon definitions, document them with stack comments, factor small words, and redefine or inspect with see.

  5. Flags and conditionals: if else then

    Lesson 5

    Flags and conditionals: if else then

    Compare with = < > 0=, combine flags with and or invert, and branch with if ... else ... then inside definitions.

  6. Loops: do loop, ?do, +loop, begin until, while

    Lesson 6

    Loops: do loop, ?do, +loop, begin until, while

    Count with do ... loop and the index i, step with +loop, skip empty ranges with ?do, and loop on conditions with begin.

  7. Variables, constants, values and memory

    Lesson 7

    Variables, constants, values and memory

    Store data with variable, read and write with @ and !, update with +!, use constant and value, and reserve arrays with allot.

  8. Characters and strings

    Lesson 8

    Characters and strings

    Print with emit and type, use s" for counted address-length strings, compare with compare, and format numbers with u.r and <# #>.

  9. The return stack: >r, r>, r@ and locals

    Lesson 9

    The return stack: >r, r>, r@ and locals

    Park values on the return stack with >r and r>, peek with r@, follow the balancing rule, and use Gforth's { } locals.

  10. Defining defining words: create does>

    Lesson 10

    Defining defining words: create does>

    Build words that make words: create gives a new name and data, does> gives all children shared behaviour, like classes in one line.

Sample certificate

Certificate of completion

Sign in to claim your certificate of completion.

Certificate

Finish all ten lessons, then sign in

Pass every lesson on this device (quizzes and checks). Then sign in or create an account to type your name and download the JPG.

All lessons