Welcome to this comprehensive tutorial series on programming in Forth using gforth!
Forth is a stack-based, concatenative programming language known for its simplicity, efficiency, and extensibility. It's been used in everything from embedded systems and firmware to space applications and scientific instruments. Forth gives you direct control over the machine while maintaining an elegant, minimalist design philosophy.
This is a hands-on, examples-based course designed to teach you Forth from the ground up. Each tutorial builds on the previous one, introducing new concepts with plenty of working examples you can try yourself.
- Basic understanding of programming concepts
- A terminal/command line environment
- gforth installed (see Setup below)
On Ubuntu/Debian:
apt-get install gforthOn macOS:
brew install gforthOn Arch Linux:
pacman -S gforthRun this command to verify gforth is working:
echo '2 3 + . bye' | gforthYou should see 5 in the output.
Simply type:
gforthTo exit, type bye and press Enter.
You can run the example files in this tutorial like this:
gforth filename.fs- Tutorial 0: Introduction to Forth - Forth philosophy, basic concepts, and your first program
- Tutorial 1: The Stack and Basic Arithmetic - Understanding the stack and doing calculations
- Tutorial 2: Stack Manipulation - Stack operations like dup, swap, drop, over, and rot
- Tutorial 3: Defining Words - Creating your own functions with
:and; - Tutorial 4: Conditionals and Logic - IF/THEN/ELSE and boolean operations
- Tutorial 5: Loops and Iteration - DO/LOOP, BEGIN/UNTIL, and other control structures
- Tutorial 6: Variables and Memory - Storing and retrieving data
- Tutorial 7: Arrays and Advanced Memory - Working with arrays and memory allocation
- Tutorial 8: Strings and Characters - String operations and character handling
- Tutorial 9: Memory Architecture & The Dictionary - Understanding Forth's memory model, the dictionary, and meta-programming
- Tutorial 10: Bit Manipulation - Bitwise operations, masks, shifts, and low-level binary manipulation
- Read each tutorial in order
- Type out the examples yourself - don't just copy-paste!
- Experiment by modifying the examples
- Complete the exercises at the end of each tutorial
- Don't rush - make sure you understand each concept before moving on
- gforth Documentation
- Thinking Forth by Leo Brodie - Classic Forth book
- Starting Forth by Leo Brodie - Another excellent introduction
Forth encourages:
- Simplicity - Keep things simple and direct
- Incrementalism - Build programs piece by piece, testing as you go
- Bottom-up design - Create a language for your problem domain
- Interactivity - Test every piece of code immediately
When you get stuck:
- Use
.sto see what's on the stack - Use
wordsto see available words - Use
see <word>to examine a word's definition - Read the error messages carefully
- Start gforth and experiment!
Ready to begin? Head to Tutorial 0: Introduction to Forth!