Next: , Previous: How does that work?, Up: Introduction


4.5 Forth is written in Forth

When you start up a Forth compiler, a large number of definitions already exist. In Forth, you develop a new application using bottom-up programming techniques to create new definitions that are defined in terms of existing definitions. As you create each definition you can test and debug it interactively.

If you have tried out the examples in this section, you will probably have typed them in by hand; when you leave Gforth, your definitions will be lost. You can avoid this by using a text editor to enter Forth source code into a file, and then loading code from the file using include (see Forth source files). A Forth source file is processed by the text interpreter, just as though you had typed it in by hand1.

Gforth also supports the traditional Forth alternative to using text files for program entry (see Blocks).

In common with many, if not most, Forth compilers, most of Gforth is actually written in Forth. All of the .fs files in the installation directory2 are Forth source files, which you can study to see examples of Forth programming.

Gforth maintains a history file that records every line that you type to the text interpreter. This file is preserved between sessions, and is used to provide a command-line recall facility. If you enter long definitions by hand, you can use a text editor to paste them out of the history file into a Forth source file for reuse at a later time (for more information see Command-line editing).


Footnotes

[1] Actually, there are some subtle differences – see The Text Interpreter.

[2] For example, /usr/local/share/gforth...