Index: > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Business Industries Finance Tax

Home > Forth programming language


First Prev [ 1 2 3 ] Next Last

Forth is a programming language and programming environment. It was initially developed by Chuck Moore at the US National Radio Astronomy Observatory ( NRAO) during the 1960s, formalized as a programming language in 1977, and standardized by ANSI in 1994. It features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal operating system), as well as the ability to compile sequences of commands into threaded code for later execution. The language is so named because Moore considered it appropriate for fourth-generation computers (i.e. microcomputers), but the system on which he developed it was limited to five-letter filenames.

1 Overview

Forth offers a standalone programming environment consisting of a stack oriented interactive incremental interpreter/ compiler. Programming is done by extending the language with 'words' (the term used for Forth subroutines), which become part of the language once defined. Forth is usually implemented with an inner interpreter tracing indirectly threaded machine code, which yields extremely compact and fast high-level code that can be compiled rapidly. A character-oriented screen/block mechanism and standard editorEditor has four major senses: # a person who obtains or improves material for a publication; # a film editor, a person responsible for the flow of a motion picture or television program from scene to scene # a sound editor, a person responsible for the fl written in Forth, provide a file mechanism for creating and storing Forth source code. A typical Forth package will consist of a pre-compiled kernel of the core words, which the programmer uses to define new words for the application. The application, once complete, can be saved as an image, with all new words already compiled. Generally, programmers will extend the initial core with words that are useful to the sorts of applications that they do, and save this as their working foundation.

FORTH has been popular for developing embedded systemAn embedded system is a special-purpose computer system usually built into a smaller device. An embedded system is required to meet very different requirements than a general-purpose personal computer. Examples of embedded systems automatic teller machines and instrument control s because it is easy to add small machine code definitions to the language and use those in an interactive high-level programming environment.

The structure of the inner interpreter is compatible with modern RISC processors, and processors that use Forth as machine language have been produced. The modular extensible nature of Forth permits many high-level applications, such as CAD systems to be written in Forth.

Forth is used in the OpenFirmware boot ROMs used by Apple and Sun. It is also used by FreeBSDFreeBSD is a Unix-like operating system descended from Unix via the BSD branch through 386BSD and 4. It runs on processors compatible with the Intel x86 family, as well as on the DEC Alpha, the UltraSPARC processors by Sun Microsystems, the Itanium (IA-64 as the first stage boot controller.

2 Forth from a programmer's perspective

Forth relies heavily on explicit use of the stack data structure and reverse Polish notationReverse Polish notation (RPN , also known as postfix notation is an arithmetic formula notation, derived from the polish notation introduced in 1920 by the Polish mathematician Jan Lukasiewicz. RPN was invented by Australian philosopher and computer scien (or RPN, also used on advanced calculators from Hewlett-Packard). This notation is also called postfix notation because the operator comes after its operands, as opposed to the more common infix notation where the operator comes between its operands. The rationale for postfix notation is that it is closer to the machine language the computer will eventually use, and should therefore be faster to execute. For example, one could get the result of a mathematical expression this way:

25 10 * 50 + .
300

This command line first puts the numbers 25 and 10 on the implied stack; the "*" command multiplies the two numbers on the top of the stack and replaces them with their product; then the number 50 is placed on the stack, and the "+" command adds it to the previous product; finally, the "." command prints the result to the user's terminal. Even the language's structural features are stack-based. For example:

: FLOOR5 DUP 5 < IF DROP 5 ELSE 1 - THEN ;

This code defines a new word (again 'word' is the term used for a subroutine) called "FLOOR5" using the following commands: "DUP" simply duplicates the number on the stack; "<" compares the two numbers on the stack and replaces them with a true-or-false value; "IF" takes a true-or-false value and chooses to execute commands immediately after it or to skip to the "ELSE"; "DROP" discards the value on the stack; and "THEN" ends the conditional. The net result is a function that performs similarly to this function (written in the C programming language):

int floor5(int v) { if (v < 5) return 5; else return v - 1; }

A terser Forth definition of FLOOR5 that gives the same result:

: FLOOR5 1 - 5 MAX ;

Forth became very popular in the 1980s because it was well suited to the small microcomputers of that time: very efficient in its use of memory and easily implemented on a new machine. At least one home computer, the British Jupiter ACE, had Forth in its ROM-resident OS. The language is still used in many small computerized devices (called embedded systems) today for three main reasons: efficient memory use, shortened development time, and fast execution speed.

Forth is also infamous as being one of the first and simplest extensible languages. That is, programmers can easily extend the language with new commands appropriate to the primary programming problem in the particular application area. Unfortunately, extensibility also helps poor programmers to write incomprehensible code. The language never achieved wide commercial use, perhaps because it acquired a reputation as a "write-only" language after several companies had product failures caused when a crucial programmer left. In addition, the ease of implementing Forth on a given processor meant that the barrier to self-development of a Forth system was quite low, so that commercial suppliers were, in effect, competing head-to-head with hobbyists, many of whom supported the idea that software should be free.

Responsible companies using the language, such as FORTH Inc , address the "write-only" problem by having internal cultures that stress code reviews.





Non User