Next: , Previous: Tutorial, Up: Top

4 An Introduction to ANS Forth

The difference of this chapter from the Tutorial (see Tutorial) is that it is slower-paced in its examples, but uses them to dive deep into explaining Forth internals (not covered by the Tutorial). Apart from that, this chapter covers far less material. It is suitable for reading without using a computer.

The primary purpose of this manual is to document Gforth. However, since Forth is not a widely-known language and there is a lack of up-to-date teaching material, it seems worthwhile to provide some introductory material. For other sources of Forth-related information, see Forth-related information.

The examples in this section should work on any ANS Forth; the output shown was produced using Gforth. Each example attempts to reproduce the exact output that Gforth produces. If you try out the examples (and you should), what you should type is shown like this and Gforth's response is shown like this. The single exception is that, where the example shows <RET> it means that you should press the “carriage return” key. Unfortunately, some output formats for this manual cannot show the difference between this and this which will make trying out the examples harder (but not impossible).

Forth is an unusual language. It provides an interactive development environment which includes both an interpreter and compiler. Forth programming style encourages you to break a problem down into many small fragments (factoring), and then to develop and test each fragment interactively. Forth advocates assert that breaking the edit-compile-test cycle used by conventional programming languages can lead to great productivity improvements.