-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Forth is a stack-based, concatenative programming language and environment originally designed by Charles H. Moore in the 1970s. It was designed to be a simple yet powerful language for system programming and embedded systems. Unlike many high-level languages that target application development, Forth is often used for low-level programming tasks such as operating system development, bootstrapping, and other system-level chores.
-
Stack-Based: Forth uses a data stack for both computation and parameter passing. The stack-based nature allows for efficient, concise code.
-
Extensible: One of the unique features of Forth is its extensibility. You can define new words (Forth's terminology for functions or procedures) in terms of existing ones. This makes Forth highly customizable.
-
Interactive: Like languages such as Lisp and Smalltalk, Forth environments are often interactive, meaning you can enter code and have it execute immediately, facilitating quick development and testing.
-
Concatenative: In Forth, complex operations are built by composing simpler ones, in a "chain" or "concatenation". This style leads to a very different sort of syntax and idioms than what's commonly found in other languages.
-
Low Overhead: Forth implementations are often extremely lightweight, which makes it suitable for embedded systems where resources are scarce.
-
Portability: Forth is often used in situations where portability across hardware is a concern, although the language itself can be quite different from one implementation to another.
Here's a very simple Forth program that calculates the square of 4:
: SQUARE ( n -- n^2 ) DUP * ;
4 SQUARE .
In this example, 4 is pushed onto the stack, SQUARE is called (which leaves 16 on the stack), and then . prints the top of the stack, displaying 16.
Forth has a dedicated following and is still in use today, particularly in embedded systems, and for certain kinds of system-level programming tasks.