FACTOID # 115: American planes take-off a staggering 8.5 million times per year - almost half the number of take-offs worldwide.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RELATED ARTICLES
People who viewed "Forth" also viewed:
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Forth
Forth
Charles H. Moore, the inventor of Forth
Charles H. Moore, the inventor of Forth
Paradigm: Procedural
Appeared in: 1970s
Designed by: Charles H. Moore
Typing discipline: Typeless
Major implementations: Forth, Inc., gForth
Dialects: colorForth, FCode
Influenced by: Burroughs B5000, Lisp, APL
Influenced: PostScript[1], Factor

Forth is a programming language and programming environment, initially developed by Charles H. Moore at the US National Radio Astronomy Observatory in the early 1970s. It was formalized in 1977 and standardized by ANSI in 1994.[2] Forth is sometimes spelled in all capital letters following the customary usage during its earlier years, although the name is not an acronym. Image File history File links ChuckMoore. ... Image File history File links ChuckMoore. ... A programming paradigm is a paradigmatic style of programming (compare with a methodology, which is a paradigmatic style of doing software engineering). ... This article or section does not cite its references or sources. ... Charles H. Moore (also known as Chuck Moore) is the inventor of the Forth programming language. ... In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ... colorForth is a programming language from the Forth programming languages original designer, Chuck Moore, developed in the late 1990s. ... There are very few or no other articles that link to this one. ... The Burroughs B5000 was a series of computers designed beginning in 1961 by a team at Burroughs under the leadership of Robert (Bob) Barton. ... Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ... APL (for A Programming Language) is an array programming language based on a notation invented in 1957 by Kenneth E. Iverson while at Harvard University. ... PostScript (PS) is a page description language and programming language used primarily in the electronic and desktop publishing areas. ... Factor is a concatenative programming language designed and implemented by Slava Pestov. ... A programming language is an artificial language that can be used to control the behavior of a machine (often a computer). ... Charles H. Moore (also known as Chuck Moore) is the inventor of the Forth programming language. ... The National Radio Astronomy Observatory (NRAO) is an institution set up by the United States government for the purpose of radio astronomy. ... The American National Standards Institute (ANSI) is a private, non-profit standards organization that produces industrial standards in the United States. ... It has been suggested that this article or section be merged with Backronym and Apronym (Discuss) Acronyms and initialisms are abbreviations, such as NATO, laser, and ABC, written as the initial letter or letters of words, and pronounced on the basis of this abbreviated written form. ...


A procedural, stack-oriented and reflective programming language without type checking, Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal operating system) and the ability to compile sequences of commands for later execution. Some Forth versions (especially early ones) compile threaded code, but many implementations today generate optimized machine code like other language compilers. This article or section does not cite its references or sources. ... A stack-oriented programming language is one that relies on a stack machine model for passing parameters. ... In computer science, reflection (or computational reflection) is the ability of a program to observe and possibly modify its structure and behavior. ... In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ... It has been suggested that this article or section be merged into Shell_(computing). ... To meet Wikipedias quality standards, this article or section may require cleanup. ... A diagram of the operation of a typical multi-language, multi-target compiler. ... In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code. ... Compiler optimization is the process of tuning the output of a compiler to minimise some attribute (or maximise the efficiency) of an executable program. ... A system of codes directly understandable by a computers CPU is termed this CPUs native or machine language. ...


Forth is so named because "[t]he file holding the interpreter was labeled FORTH, for 4th (next) generation software - but the operating system restricted file names to 5 characters."[3] Moore's use of the phrase 4th (next) generation software appears to predate the definition of fourth-generation programming languages; he saw Forth as a successor to compile-link-go third-generation programming languages, or software for "4th generation" hardware, not a 4GL as we understand the term today. A fourth-generation programming language (abbreviated 4GL) is a programming language designed with a specific purpose in mind, such as the development of commercial business software. ... A third generation language (3GL) is a programming language designed to be easier for a human to understand, including things like named variables. ...

Contents


Overview

Forth offers a standalone programming environment consisting of a stack-oriented, interactive, incremental interpreter and compiler. Programming is done by extending the language with words (the term used for Forth subroutines), which become part of the language once defined. A typical Forth package consists of a pre-compiled kernel of the core words, which the programmer uses to define new words for the application. The completed application can be saved as an image, with the new words already compiled. Generally programmers extend the initial core with words that are useful to the types of applications that they write, and save this as their working foundation. A stack-oriented programming language is one that relies on a stack machine model for passing parameters. ... An interpreter is a computer program that executes other programs. ... A diagram of the operation of a typical multi-language, multi-target compiler. ... In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. ...


Forth uses separate stacks for storage of subroutine parameters and subroutine activation records. The parameter or data stack (commonly referred to as the stack) is used to pass data to words and to store the results the words return. The linkage or return stack (commonly referred to as the rstack) is used to store return addresses when words are nested (the equivalent of a subroutine call), and store local variables. There are standard words to move data between the stacks, and to load and store variables on the stack. It has been suggested that this article or section be merged into Subroutine. ... In computing, a stack frame is a data structure used to create temporary storage for data and saved state in functions. ... In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. ...


The logical structure of Forth resembles a virtual machine. Forth, especially early versions, implements an inner interpreter tracing indirectly threaded machine code, giving compact and fast high-level code that can be compiled rapidly. More modern implementations generate optimized machine code like other language compilers. In general terms, a virtual machine in computer science is software that creates a virtualized environment between the computer platform and the end user in which the end user can operate software. ... In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code. ... A system of codes directly understandable by a computers CPU is termed this CPUs native or machine language. ...


Forth became very popular in the 1980s[4] because it was well suited to the small microcomputers of that time, as it is compact and portable. At least one home computer, the British Jupiter ACE, had Forth in its ROM-resident OS. Forth is still used today in many embedded systems (small computerized devices) because of its portability, efficient memory use, short development time, and fast execution speed. It has been implemented efficiently on modern RISC processors, and processors that use Forth as machine language have been produced.[5] Other uses of Forth include the Open Firmware boot ROMs used by Apple, IBM and Sun and as the first stage boot controller of the FreeBSD operating system. The Commodore 64 was one of the most popular microcomputers of its era, and is the best selling home computer of all time. ... TRS-80 Color Computer II The home computer is a consumer-friendly word for the second generation of microcomputers (the technical term that was previously used), entering the market in 1977 and becoming common during the 1980s. ... The Jupiter ACE was a British home computer of the 1980s, marketed by a company named Jupiter Cantab. ... Read-only memory (ROM) is a class of storage media used in computers and other electronic devices. ... A router, an example of an embedded system. ... In computer science, porting is the adaptation of a piece of software so that it will function in a different computing environment to that for which it was originally written. ... This article is about the computer architecture. ... In computer science, a stack machine is a model of computation in which the computers memory takes the form of a stack. ... Open Firmware (also, OpenBoot) is a hardware-independent firmware (computer software which loads the operating system), developed by Sun Microsystems, and used in post-NuBus PowerPC-based Apple Macintosh computers, Sun Microsystems SPARC based workstations and servers, IBM POWER systems, and PegasosPPC systems, among others. ... An Internet payphone loading Windows XP In computing, booting is a bootstrapping process that starts operating systems when the user turns on a computer system. ... Apple Computer, Inc. ... now. ... Sun Microsystems, Inc. ... BTX is the standard FreeBSD and DragonflyBSD boot loader. ... FreeBSD is a Unix-like free operating system descended from AT&T UNIX via the Berkeley Software Distribution (BSD) branch through 386BSD and 4. ...


Forth is a simple yet extensible language; its modularity and extensibility permit the writing of high-level programs such as CAD systems. However, extensibility also helps poor programmers to write incomprehensible code, which has given Forth a reputation as a "write-only" language. Forth has been used successfully in large, complex projects, while applications developed by competent, disciplined professionals have proven to be easily maintained on evolving hardware platforms over decades of use.[6] CAD redirects here. ... A write-only language is a programming language with the attribute that programs written in it are more easily scrapped and re-written than modified. ...


Programmer's perspective

Forth relies heavily on explicit use of a data stack and reverse Polish notation (RPN or postfix notation), commonly used in calculators from Hewlett-Packard. In RPN, the operator is placed after its operands, as opposed to the more common infix notation where the operator is placed between its operands. Postfix notation makes the language easier to parse and extend; Forth does not use a BNF grammar, and does not have a monolithic compiler. Extending the compiler only requires writing a new word, instead of modifying a grammar and changing the underlying implementation. A stack is a data structure that works on the principle of Last In First Out (LIFO). ... Reverse Polish notation (RPN), also known as postfix notation, was invented by Australian philosopher and computer scientist Charles Hamblin in the mid-1950s, to enable zero-address memory stores. ... The Hewlett-Packard Company (NYSE: HPQ), commonly known as HP, is a very large, global company headquartered in Palo Alto, California, United States. ... Infix notation is the common arithmetic and logical formula notation, in which operators are written infix-style between the operands they act on (e. ... The Backus-Naur form (BNF) (also known as Backus normal form) is a metasyntax used to express context-free grammars: that is, a formal way to describe formal languages. ...


Using RPN, one could get the result of the mathematical expression (25 * 10 + 50) this way:

 25 10 * 50 + . 300 ok 

This command line first puts the numbers 25 and 10 on the implied stack.

The word * multiplies the two numbers on the top of the stack and replaces them with their product. Image File history File links Stack1. ...

Then the number 50 is placed on the stack. No file by this name exists; you can upload it. ...

The word + adds it to the previous product. Finally, the . command prints the result to the user's terminal.[7] Image File history File links Forthstack2. ...

Even Forth's structural features are stack-based. For example: Image File history File links Forthstack3. ...

 : FLOOR5 ( n -- n' ) DUP 6 < 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 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 text in parentheses is a comment, advising that this word expects a number on the stack and will return a possibly changed number. The net result performs similarly to this function written in the C programming language: Wikibooks has a book on the topic of C Programming The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...

 int floor5(int v) { return v < 6 ? 5 : v - 1; } 

Facilities

Interpreter

Forth parsing is simple, as it has no explicit grammar. The interpreter reads a line of input from the user input device, which is then parsed for a word using spaces as a delimiter; some systems recognise additional whitespace characters. When the interpreter finds a word, it tries to look the word up in the dictionary. If the word is found, the interpreter executes the code associated with the word, and then returns to parse what is left of the input stream. If the word isn't found, the word is assumed to be a number, and an attempt is made to convert it into a number and push it on the stack; if successful, the interpreter continues parsing the input stream. Otherwise, if both the lookup and number conversion fails, the interpreter prints the word followed by an error message indicating the word is not recognised, flushes the input stream, and waits for new user input.[8] In computer science, parsing is the process of analyzing an input sequence (read from a file or a keyboard, for example) in order to determine its grammatical structure with respect to a given formal grammar. ... Grammar is the study of rules governing the use of language. ... Delimiters are marks which are used to seperate subfields of data. ... For information on the programming language Whitespace, see Whitespace programming language. ...


Compiler

The definition of a new word is started with the word : (colon) and ends with the word ; (semi-colon). For example

 : X DUP 1+ . . ; 

will compile the word X. When executed by typing 10 X at the console this will print 11 10.[9]


Assembler

Most Forth systems include a specialized assembler that produces executable words. The assembler is a special dialect of the compiler. Forth assemblers often use a reverse-polish syntax in which the parameters of an instruction precede the instruction. The usual design of a Forth assembler is to construct the instruction on the stack, then copy it into memory as the last step. Registers may be referenced by the name used by the manufacturer, numbered (0..n, as used in the actual operation code) or named for their purpose in the Forth system: e.g. "S" for the register used as a stack pointer.[10] To meet Wikipedias quality standards, this article or section may require cleanup. ...


Operating system, files and multitasking

Classic Forth systems traditionally use no operating system nor file system. Instead of storing code in files, source-code is stored in disk blocks written to physical disk addresses. The word BLOCK is employed to translate the number of a 1K-sized block of disk space into the address of a buffer containing the data, which is managed automatically by the Forth system. Some implement contiguous disk files using the system's disk access, where the files are located at fixed disk block ranges. Usually these are implemented as fixed-length binary records, with an integer number of records per disk block. Quick searching is achieved by hashed access on key data. To meet Wikipedias quality standards, this article or section may require cleanup. ... In computing, a file system is a method for storing and organizing computer files and the data they contain to make it easy to find and access them. ...


Multitasking, most commonly cooperative round-robin scheduling is normally available (although multitasking words and support are not covered by the ANSI Forth Standard). The word PAUSE is used to save the current task's execution context, to locate the next task, and restore its execution context. Each task has its own stacks, private copies of some control variables and a scratch area. Swapping tasks is simple and efficient; as a result, Forth multitaskers are available even on very simple microcontrollers such as the Intel 8051, Atmel AVR, and TI MSP430.[11] In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is... In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is... Round-robin is one of the simplest scheduling algorithms for processes in an operating system, which assigns time slices to each process in equal portions and in order, handling all processes as having the same priority. ... A microcontroller (or MCU) is a computer-on-a-chip used to control electronic devices. ... Pin diagram of 40 pin Intel 8051 Microcontroller The Intel 8051 was a Harvard architecture single chip microcontroller (µC) developed by Intel in 1980 for use in embedded systems. ... The AVR®s are a family of RISC microcontrollers from Atmel. ... The MSP430 is a microcontroller family from Texas Instruments. ...


By contrast, some Forth systems run under a host operating system such as Microsoft Windows, Linux or a version of Unix and use the host operating system's file system for source and data files; the ANSI Forth Standard describes the words used for I/O. Other non-standard facilities include a mechanism for issuing calls to the host OS or windowing systems, and many provide extensions that employ the scheduling provided by the operating system. Typically they have a larger and different set of words from the stand-alone Forth's PAUSE word for task creation, suspension, destruction and modification of priority. Microsoft Windows is a family of operating systems by Microsoft. ... Linux (also known as GNU/Linux) is a Unix-like computer operating system. ... Unix or UNIX is a computer operating system originally developed in the 1960s and 1970s by a group of AT&T Bell Labs employees including Ken Thompson, Dennis Ritchie, and Douglas McIlroy. ... In computing, a system call is the mechanism used by an application program to request service from the operating system, or more specifically, the operating system kernel. ... A windowing system is a graphical user interface (GUI) which uses the window as one of its primary metaphors. ...


Self compilation and cross compilation

A full-featured Forth system with all source code will compile itself, a technique commonly called meta-compilation by Forth programmers (although the term doesn't exactly match meta-compilation as it is normally defined). The usual method is to redefine the handful of words that place compiled bits into memory. The compiler's words use specially-named versions of fetch and store that can be redirected to a buffer area in memory. The buffer area simulates or accesses a memory area beginning at a different address than the code buffer. Such compilers define words to access both the target computer's memory, and the host (compiling) computer's memory.[12] Metacompilation is a computation which involves metasystem transitions (MST for short) from a computing machine M to a metamachine M which controls, analyzes and imitates the work of M. Semantics-based program transformation, such as partial evaluation and supercompilation (SCP), is metacomputation. ...


After the fetch and store operations are redefined for the code space, the compiler, assembler, etc. are recompiled using the new definitions of fetch and store. This effectively reuses all the code of the compiler and interpreter. Then, the Forth system's code is compiled, but this version is stored in the buffer. The buffer in memory is written to disk, and ways are provided to load it temporarily into memory for testing. When the new version appears to work, it is written over the previous version.


There are numerous variations of such compilers for different environments. For embedded systems, the code may instead be written to another computer, a technique known as cross compilation, over a serial port or even a single TTL bit, while keeping the word names and other non-executing parts of the dictionary in the original compiling computer. The minimum definitions for such a forth compiler are the words that fetch and store a byte, and the word that commands a forth word to be executed. Often the most time-consuming part of a remote port is to construct the initial program to implement fetch, store and execute. Many modern microprocessors have integrated debugging features (such as the Motorola CPU32) that eliminate even this task.[13] A router, an example of an embedded system. ... Compiling a program takes place by running a compiler on the build platform. ... A Motorola 68000-based computer with various TTL chips. ... The Motorola 683XX aka CPU32 is a family of compatible microcontrollers that use a Motorola 68000 CPU core. ...


Structure of the language

The basic data structure of Forth is the "dictionary" which maps "words" to executable code or named data structures. The dictionary is laid out in memory as a linked list with the links proceeding from the latest (most recently) defined word to oldest, until a sentinel, usually a NULL pointer, is found. In computer science, a linked list is one of the fundamental data structures used in computer programming. ...


A defined word generally consists of head and body with the head consisting of the name field (NF) and the link field (LF) and body consisting of the code field (CF) and the parameter field (PF).


Head and body of a dictionary entry are treated separately because they may not be contiguous. For example, when a Forth program is recompiled for a new platform, the head may remain on the compiling computer, while the body goes to the new platform. In some environments (such as embedded systems) the heads occupy memory unnecessarily. However, some cross-compilers may put heads in the target if the target itself is expected to support an interactive Forth.[14] A router, an example of an embedded system. ...


Dictionary entry

The exact format of a dictionary entry is not prescribed, and implementations vary. However, certain components are almost always present though the exact size and order may vary. Described as a structure, a dictionary entry might look this way:[15]

 structure byte: flag  3bit flags + length of word's name char-array: name  name's runtime length isn't known at compile time address: previous  link field, backward ptr to previous word address: codeword  ptr to the code to execute this word any-array: parameterfield  unknown length of data, words, or opcodes end-structure forthword 

The name field starts with a prefix giving the length of the word's name (typically up to 32 bytes), and several bits for flags. The character representation of the word's name then follows the prefix. Depending on the particular implementation of Forth, there may be one or more NUL ('0') bytes for alignment.


The link field contains a pointer to the previously defined word. The pointer may be a relative displacement or an absolute address that points to the next oldest sibling.


The code field pointer will be either the address of the word which will execute the code or data in the parameter field or the beginning of machine code that the processor will execute directly. For colon defined words, the code field pointer points to the word that will save the current Forth instruction pointer (IP) on the return stack, and load the IP with the new address from which to continue execution of words. This is the same as what a processor's call/return instructions does.


Structure of the compiler

The compiler itself consists of Forth words visible to the system, not a monolithic program. This allows a programmer to change the compiler's words for special purposes.


The "compile time" flag in the name field is set for words with "compile time" behavior. Most simple words execute the same code whether they are typed on a command line, or embedded in code. When compiling these, the compiler simply places code or a threaded pointer to the word.[9]


Compile-time words are actually executed by the compiler. The classic examples of compile-time words are the control structures such as IF and WHILE. All of Forth's control structures, and almost all of its compiler are implemented as compile-time words. In computer science and in computer programming, statements in pseudocode or in a program are normally obeyed one after the other in the order in which they are written (sequential flow of control). ...


Compilation state and interpretation state

The word : (colon) takes a name as a parameter, creates a dictionary entry (a colon definition) and enters compilation state. The interpreter continues to read space-delimited words from the user input device. If a word is found, the interpreter executes the compilation semantics associated with the word, instead of the interpretation semantics. The default compilation semantics of a word are to append its interpretation semantics to the current definition.[9]


The word ; (semi-colon) finishes the current definition and returns to interpretation state. It is an example of a word whose compilation semantics differ from the default. The interpretation semantics of ; (semi-colon) and several other words are undefined in ANS Forth.[9]


The interpreter state can be changed manually with the words [ (left-bracket) and ] (right-bracket) which enter interpretation state or compilation state, respectively. These words can be used with the word LITERAL to calculate a value during a compilation and to insert the calculated value into the current colon definition. LITERAL has the compilation semantics to take an object from the data stack and to append semantics to the current colon definition to place that object on the data stack.


In ANS Forth, the current state of the interpreter can be read from the flag STATE which contains the value true when in compilation state and false otherwise. This allows the implementation of so-called state-smart words with behavior that changes according to the current state of the interpreter. In computer programming, flag refers to one or more bits that are used to store a binary value or code that has an assigned meaning. ...


Immediate words

The word IMMEDIATE marks the most recent colon definition as an immediate word, effectively replacing its compilation semantics with its interpretation semantics.[16] Immediate words are always executed, not compiled, in either state. ; is an example of an immediate word. In ANS Forth, the word POSTPONE takes a name as a parameter and appends the compilation semantics of the named word to the current definition even if the word was marked immediate. Forth-83 defined separate words COMPILE and [COMPILE] to force the compilation of non-immediate and immediate words, respectively.


Unnamed words and execution tokens

In ANS Forth, unnamed words can be defined with the word :NONAME which compiles the following words up to the next ; (semi-colon) and leaves an execution token on the data stack. The execution token provides an opaque handle for the compiled semantics, similar to the function pointers of the C programming language. A function pointer is a type of pointer in the C and C++ programming languages. ... Wikibooks has a book on the topic of C Programming The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...


Execution tokens can be stored in variables. The word EXECUTE takes an execution token from the data stack and performs the associated semantics. The word COMPILE, (compile-comma) takes an execution token from the data stack and appends the associated semantics to the current definition.


The word ' (tick) takes the name of a word as a parameter and returns the execution token associated with that word on the data stack. In interpretation state, ' RANDOM-WORD EXECUTE is equivalent to RANDOM-WORD.[17]


Parsing words and comments

The words : (colon), POSTPONE, ' (tick) and :NONAME are examples of parsing words that take their arguments from the user input device instead of the data stack. Another example is the word ( (paren) which reads and ignores the following words upto and including the next right parenthesis and is used to place comments in a colon definition. Similarly, the word (backslash) is used for comments that continue to the end of the current line. To be parsed correctly, ( (paren) and (backslash) must be separated by whitespace from the following comment text.


Structure of code

In most Forth systems, the body of a code definition consists of either machine language, or some form of threaded code. Traditionally, indirect-threaded code was used, but direct-threaded and subroutine threaded Forths have also been popular. The fastest modern Forths use subroutine threading, insert simple words as macros, and perform peephole optimization or other optimizing strategies to make the code smaller and faster.[18] A system of codes directly understandable by a computers CPU is termed this CPUs native or machine language. ... In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code. ... In compiler theory, peephole optimization is a kind of optimization performed over a very small set of instructions in a segment of generated code. ...


Data objects

When a word is a variable or other data object, the CF points to the runtime code associated with the defining word that created it. A defining word has a characteristic "defining behavior" (creating a dictionary entry plus possibly allocating and initializing data space) and also specifies the behavior of an instance of the class of words constructed by this defining word. Examples include:

VARIABLE
Names an uninitialized, one-cell memory location. Instance behavior of a VARIABLE returns its address on the stack.
CONSTANT
Names a value (specified as an argument to CONSTANT). Instance behavior returns the value.
CREATE
Names a location; space may be allocated at this location, or it can be set to contain a string or other initialized value. Instance behavior returns the address of the beginning of this space.

Forth also provides a facility by which a programmer can define new application-specific defining words, specifying both a custom defining behavior and instance behavior. Some examples include circular buffers, named bits on an I/O port, and automatically-indexed arrays.


Data objects defined by these and similar words are global in scope. The function provided by local variables in other languages is provided by the data stack in Forth. Forth programming style uses very few named data objects compared with other languages; typically such data objects are used to contain data which is used by a number of words or tasks (in a multitasked implementation).[19]


Forth does not enforce consistency of data type usage; it is the programmer's responsibility to use appropriate operators to fetch and store values or perform other operations on data.


Programming

Words written in Forth are compiled into an executable form. The classical "indirect threaded" implementations compile lists of addresses of words to be executed in turn; many modern systems generate actual machine code (including calls to some external words and code for others expanded in place). Some systems have optimizing compilers. Generally speaking, a Forth program is saved as the memory image of the compiled program with a single command (e.g., RUN) that is executed when the compiled version is loaded.


During development, the programmer uses the interpreter to execute and test each little piece as it is developed. Most Forth programmers therefore advocate a loose top-down design, and bottom-up development with continuous testing and integration.[20]


The top-down design is usually separation of the program into "vocabularies" that are then used as high-level sets of tools to write the final program. A well-designed Forth program reads like natural language, and implements not just a single solution, but also sets of tools to attack related problems.


The tool-box approach is one of the reasons that Forth is so difficult to master. While learning the syntax is easy, mastering the tools delivered with a professional Forth system can take several months, working full-time. The task is actually more difficult than rewriting one's own Forth system from scratch. Unfortunately, a rewrite also loses the experience accumulated in a typical professional Forth toolbox.[21]


Code examples

Hello world

For an explanation of the tradition of programming "Hello World", see Hello world program. A hello world program is a software program that prints out Hello, world! on a display device. ...


One possible implementation:

 : HELLO ( -- ) CR ." Hello, world!" ; HELLO 

The word CR causes the following output to be displayed on a new line. The parsing word ." (dot-quote) reads a double-quote delimited string and appends code to the current definition so that the parsed string will be displayed on execution. The space character separating the word ." from the string Hello, world! is not included as part of the string. It is needed so that the parser recognizes ." as a Forth word.


A standard Forth system is also an interpreter, and the same output can be obtained by typing the following code fragment into the Forth console:

 CR .( Hello, world!) 

.( (dot-paren) is an immediate word that parses a parenthesis-delimited string and displays it. As with the word ." the space character separating .( from Hello, world! is not part of the string.


The word CR comes before the text to print. By convention, the Forth interpreter does not start output on a new line. Also by convention, the interpreter waits for input at the end of the previous line, after an ok prompt. There is no implied 'flush-buffer' action in Forth's CR, as sometimes is in other programming languages.


Mixing compilation state and interpretation state

Here is the definition of a word EMIT-Q which when executed emits the single character Q:

 : EMIT-Q 81 ( the ASCII value for the character 'Q' ) EMIT ; 

This definition was written to use the ASCII value of the Q character (81) directly. The text between the parentheses is a comment and is ignored by the compiler. The word EMIT takes a value from the data stack and displays the corresponding character. There are 95 printable ASCII characters, numbered 32 to 126. ...


The following redefinition of EMIT-Q uses the words [ (left-bracket), ] (right-bracket), CHAR and LITERAL to temporarily switch to interpreter state, calculate the ASCII value of the Q character, return to compilation state and append the calculated value to the current colon definition:

 : EMIT-Q [ CHAR Q ] LITERAL EMIT ; 

The parsing word CHAR takes a space-delimited word as parameter and places the value of its first character on the data stack. The word [CHAR] is an immediate version of CHAR. Using [CHAR], the example definition for EMIT-Q could be rewritten like this:

 : EMIT-Q [CHAR] Q EMIT ;  Emit the single character 'Q' 

This definition used (backslash) for the describing comment.


Both CHAR and [CHAR] are predefined in ANS Forth. Using IMMEDIATE and POSTPONE, [CHAR] could have been defined like this:

 : [CHAR] CHAR POSTPONE LITERAL ; IMMEDIATE 

See also

In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code. ... The Jupiter ACE was a British home computer of the 1980s, marketed by a company named Jupiter Cantab. ... PostScript (PS) is a page description language and programming language used primarily in the electronic and desktop publishing areas. ... The RPL programming language (RPL meaning reverse Polish LISP or, alternatively, ROM-based procedural language) is a handheld calculator system and application programming language used on Hewlett-Packards engineering graphing RPN calculators of the HP-28, HP-48 and HP-49 series. ... There are very few or no other articles that link to this one. ...

Footnotes

  1. ^ (1985) “First”, PostScript Language - Tutorial and Cookbook (paperback), Adobe Systems Inc., First (in English), Addison-Wesley, 243. ISBN 0-201-10179-3. “The PostScript language contains elements of many programming languages, but most closely resembles the Forth language.”
  2. ^ ANSI technical committee X3J14 (1994-03-24). Programming Languages: Forth (English) (HTML). Retrieved on 2006-06-03.
  3. ^ Moore, Charles H. (1991). Forth - The Early Years (English) (HTML). Retrieved on 2006-06-03.
  4. ^ … (1980), "The Forth Language", BYTE Magazine, vol. 5, no. 8
  5. ^ Forth Chips Page (English). Retrieved on 2006-06-09.
  6. ^ Forth Success Stories. Retrieved on 2006-06-09.
  7. ^ Brodie, Leo (1987). Starting Forth (paperback), Second (in English), Prentice-Hall, 20. ISBN 0-13-843079-9.
  8. ^ Brodie, Leo (1987). Starting Forth (paperback), Second (in English), Prentice-Hall, 14. ISBN 0-13-843079-9.
  9. ^ a b c d Brodie, Leo (1987). Starting Forth (paperback), Second (in English), Prentice-Hall, 16. ISBN 0-13-843079-9.
  10. ^ Rodriguez, Brad. B.Y.O.ASSEMBLER (English) (HTML). Retrieved on 2006-06-19.
  11. ^ Rodriguez, Brad. MULTITASKING 8051 CAMELFORTH (English) (PDF). Retrieved on 2006-06-19.
  12. ^ Rodriguez, Brad (July 1995). MOVING FORTH (English) (HTML). Retrieved on 2006-06-19.
  13. ^ Shoebridge, Peter (1998-12-21). Motorola Background Debugging Mode Driver for Windows NT (English) (HTML). Retrieved on 2006-06-19.
  14. ^ Martin, Harold M. (March 1991). Developing a tethered Forth model (English). ACM Press. Retrieved on 2006-06-19.
  15. ^ Brodie, Leo (1987). Starting Forth (paperback), Second (in English), Prentice-Hall, 200-202. ISBN 0-13-843079-9.
  16. ^ Brodie, Leo (1987). Starting Forth (paperback), Second (in English), Prentice-Hall, 273. ISBN 0-13-843079-9.
  17. ^ Brodie, Leo (1987). Starting Forth (paperback), Second (in English), Prentice-Hall, 199. ISBN 0-13-843079-9.
  18. ^ Ertl, M. Anton; Gregg, David. Implementation Issues for Superinstructions in Gforth (English) (PDF). Retrieved on 2006-06-19.
  19. ^ Brodie, Leo (1987). “Under The Hood”, Starting Forth (paperback), 2nd, Prentice-Hall, 241. ISBN 0-13-843079-9. “To summarize, there are three kinds of variables: System variables contain values used by the entire Forth system. User variables contain values that are unique for each task, even though the definitions can be used by all tasks in the system. Regular variables can be accessible either system-wide or within a single task only, depending upon whether they are defined within OPERATOR or within a private task.”
  20. ^ Brodie, Leo (1984). Thinking Forth (paperback), Prentice-Hall. ISBN 0-13-917568-7.
  21. ^ Ertl, M. Anton (2003-08-25). Gforth Manual (English) (HTML). Retrieved on 2006-06-20.

2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 3 is the 154th day of the year in the Gregorian calendar (155th in leap years), with 211 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 3 is the 154th day of the year in the Gregorian calendar (155th in leap years), with 211 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 9 is the 160th day of the year in the Gregorian calendar (161st in leap years), with 205 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 9 is the 160th day of the year in the Gregorian calendar (161st in leap years), with 205 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 1998 (MCMXCVIII) was a common year starting on Thursday of the Gregorian calendar, and was designated the International Year of the Ocean. ... December 21 is the 355th day of the year (356th in leap years) in the Gregorian calendar. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 2003 (MMIII) was a common year starting on Wednesday of the Gregorian calendar. ... August 25 is the 237th day of the year in the Gregorian Calendar (238th in leap years), with 128 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 20 is the 171st day of the year (172nd in leap years) in the Gregorian Calendar, with 194 days remaining. ...

References

  • Brodie, Leo (1987). Starting Forth (paperback), 2nd edition (in English), Prentice-Hall. ISBN 0-13-843079-9. Retrieved on 2006-06-19.
  • Brodie, Leo (1984). Thinking Forth (paperback) (in English), Prentice-Hall. ISBN 0-13-917568-7. Retrieved on 2006-06-19.
  • Conklin, Edward K., Elizabeth D. Rather et al. Forth Programmer's Handbook (paperback) (in English), Forth Inc., 240. ISBN 0-9662156-0-5.
  • Kelly, Mahlon G., Nicholas Spies. FORTH: A Text and Reference (in English). Prentice-Hall. ISBN 0-13-326331-2.
  • Pountain, Dick (1987). Object-oriented Forth: Implementation of Data Structures (paperback) (in English), Harcourt Brace Jovanovich. ISBN 0-12-563570-2.

2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ... 2006 (MMVI) is a common year starting on Sunday of the Gregorian calendar. ... June 19 is the 170th day of the year (171st in leap years) in the Gregorian Calendar, with 195 days remaining. ...

External links

Wikibooks
Wikibooks has more about this subject:

Image File history File links Wikibooks-logo-en. ... TRS-80 Color Computer II The home computer is a consumer-friendly word for the second generation of microcomputers (the technical term that was previously used), entering the market in 1977 and becoming common during the 1980s. ...

Tutorials

History

Historical implementations

  • GraFORTH — Forth for the Apple ][ with audio and graphics primitives (ShrinkIt archive)
  • MVP Forth with source code available from Mountain View Press
  • Pocket Forth, a very old Macintosh-specific Forth implementation with source code in 680x0 assembly language
  • volksFORTH a 16bit Forth System for MS-DOS, Atari Portfolio, CP/M, Atari ST, Amstrad CPC, Apple 1/Replica 1, Atari XL/XE, Commodore PET, C64, C16, Plus/4

The 68000 grew out of the MACSS (Motorola Advanced Computer System on Silicon) project, begun in 1976. ... To meet Wikipedias quality standards, this article or section may require cleanup. ...

Historical standards

  • The Forth-79 Standard
  • The Forth-83 Standard

  Results from FactBites:
 
Forth ONE (312 words)
Forth One & Vodafone want to give you chances to win…If you’re at work we want you to play ‘Just The Job’.
If you’re a small business and feel you have skills which might be of use then click here.
Share your views by registering with our listener survey and you could help shape the sound of Forth One.
A Brief Introduction to Forth (1166 words)
At a deeper level, Forth programs use RPN not as an end in itself, but rather as a means to achieve simple syntax and flexible modularity.
This example follows the Forth convention of including a stack-effect comment showing that a (the second stack element) and b (the top stack element) are consumed as stack inputs, with c produced as the stack output.
Permission to copy without fee all or part of this material is granted, provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its data appear, and notice is given that copying is by permission of the Association for Computing Machinery.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.