comp.lang.forth Frequently Asked Questions (1/6): Gen- eral/Misc M. Anton Ertl, anton@mips.complang.tuwien.ac.at ____________________________________________________________ Table of Contents: 1. Acknowledgements 2. comp.lang.forth FAQs 3. General Questions 3.1. What is Forth? 3.2. Why and where is Forth used? 3.3. What language standards exist for Forth? 3.4. What is an RFI? 3.5. What is the Forth Interest Group? 4. Flame baits 4.1. Commercial vs. free Forth systems 4.2. Free Forth systems are bad for Forth. 4.3. Blocks vs. files 5. Miscellaneous 5.1. Where can I find a C-to-Forth compiler? 5.2. Where can I find a Forth-to-C compiler? 5.3. RECORDS in Forth? 5.4. Why does THEN finish an IF structure? ______________________________________________________________________ 1. Acknowledgements This FAQ is based on previous work by Gregory Haverkamp, J. D. Verne, and Bradford J. Rodriguez. 2. comp.lang.forth FAQs The comp.lang.forth FAQ is published in six parts, corresponding to these six sections. This part is the General/Misc FAQ, where the questions not covered in the other FAQs are answered. The six parts are: o General questions o Online resources o Forth vendors o Forth systems o Books, periodicals, tutorials o Forth groups & organizations These FAQs are intended to be a brief overview of the tools and information available for the new FORTHer. For a historical reference, programming paradigms, and deep technical information try some of the listed references. For general questions on the internet, or the methods used to get this information, try these other Usenet groups: o news.announce.newusers o news.newusers.questions o news.announce.important 3. General Questions 3.1. What is Forth? Forth is a stack-based, extensible language without type-checking. It is probably best known for its "reverse Polish" (postfix) arithmetic notation, familiar to users of Hewlett-Packard calculators: to add two numbers in Forth, you would type 3 5 + instead of 3+5. The fundamental program unit in Forth is the "word": a named data item, subroutine, or operator. Programming in Forth consists of defining new words in terms of existing ones. The Forth statement ______________________________________________________________________ : SQUARED DUP * ; ______________________________________________________________________ defines a new word SQUARED whose function is to square a number (mul- tiply it by itself). Since the entire language structure is embodied in words, the application programmer can "extend" Forth to add new operators, program constructs, or data types at will. The Forth "core" includes operators for integers, addresses, characters, and Boolean values; string and floating-point operators may be optionally added. 3.2. Why and where is Forth used? Although invented in 1970, Forth became widely known with the advent of personal computers, where its high performance and economy of memory were attractive. These advantages still make Forth popular in embedded microcontroller systems, in locations ranging from the Space Shuttle to the bar-code reader used by your Federal Express driver. Forth's interactive nature streamlines the test and development of new hardware. Incremental development, a fast program-debug cycle, full interactive access to any level of the program, and the ability to work at a high "level of abstraction," all contribute to Forth's reputation for very high programmer productivity. These, plus the flexibility and malleability of the language, are the reasons most cited for choosing Forth for embedded systems. 3.3. What language standards exist for Forth? An American National Standard for Forth, ANSI X3.215-1994, is accepted worldwide as the definitive Forth standard. ("ANS Forth") IEEE Standard 1275-1994, the "Open Firmware" standard, is a Forth derivative which has been adopted by Sun Microsystems, HP, Apple, IBM, and others as the official language for writing bootstrap and driver firmware. Prior Forth standards include the Forth-83 Standard and the Forth-79 Standard issued by the Forth Standards Team. The earlier FIG-Forth, while never formally offered as such, was a de facto "standard" for some years. "FORTH STANDARDS Published standards since 1978 are Forth 79 and Forth 83 from the Forth Standard Team, and ANS Forth - document X3.215-1994 - by the X3J14 Technical Committee. The most recent standard, ANS Forth, defines a set of core words and some optional extensions and takes care to allow great freedom in how these words are implemented. The range of hardware which can support an ANS Forth Standard System is far wider than any previous Forth standard and probably wider than any programming language standard ever. See web page for latest details. Copies of the standard cost $193, but the final draft of ANS Forth is free and available (subject to copyright restrictions) via ftp..." --Chris Jakeman, apvpeter.demon.co.uk The (un)official ANS Forth document is available in various formats at and at To get yourself on the ANS-Forth mailing list, consult the various README files at . Two unofficial test suites are available for checking conformance to the ANS Standard Forth: o John Hayes has written a test suite to test ANS Standard Systems (available through ). o JET Thomas has written a test suite to test ANS Standard Programs: 3.4. What is an RFI? A Request For Interpretation. If you find something in the standard document ambiguous or unclear, you can make an RFI, and the TC (technical committee), that produced the standard, will work out a clarification. You can make an RFI by mailing it to greg@minerva.com and labeling it as RFI. The answers to earlier RFIs are available at ftp://ftp.uu.net/vendor/minerva/x3j14/queries/. 3.5. What is the Forth Interest Group? The Forth Interest Group "FIG" was formed in 1978 to disseminate information and popularize the Forth language, and it remains the premier organization for professional Forth programmers. FIG maintains a Web page at , with a more complete introduction to the Forth language, and links to the Web pages of many Forth vendors. 4. Flame baits Some statements spawn long and heated discussions where the participants repeat their positions and ignore the arguments of the other side (flame wars). You may want to avoid such statements. Here, I present some regularly appearing flame baits and the positions you will read (so you don't have to start a flame war to learn them). 4.1. Commercial vs. free Forth systems "You get what you pay for. With a commercial Forth you get commercial documentation and support. We need commercial Forth systems or Forth will die." "I have had good experiences with free Forths. I cannot afford a commercial Forth system. I want source code (some commercial vendors don't provide it for the whole system). Examples of bad support from commercial software vendors. Without free Forth systems Forth will die." 4.2. Free Forth systems are bad for Forth. "Anyone can write a bad Forth and give it away without documentation or support; after trying such a system, nobody wants to work with Forth anymore. Free Forths give Forth a bad name. Free Forths take business away from the vendors." "Many people learned Forth with fig-Forth. There are good free Forths. Most successful languages started with (and still have) free implementations. Languages without free implementations (like Ada, Eiffel and Miranda) are not very popular." 4.3. Blocks vs. files The discussions on this topic are much cooler since Mike Haas has dropped from comp.lang.forth. "Everyone is using files and all third-party tools are designed for files. Files waste less space. Blocks lead to horizontal, unreadable code. Blocks make Forth ridiculous." "We are not always working under an operating system, so on some machines we don't have files. We have very nice block editors and other tools and coding standards for working with blocks (e.g., shadow screens)." 5. Miscellaneous 5.1. Where can I find a C-to-Forth compiler? There have been roumors about such a compiler at Harris (for the RTX chip) and elsewhere. The most concrete answer to this question has come from Stephen Pelc (sfp@mpeltd.demon.co.uk): MPE has produced a C to stack-machine compiler. This generates tokens for a 2-stack virtual machine. The code quality is such that the token space used by compiled programs is better than that of the commercial C compilers we have tested against. This a consequence of the virtual machine design. However, to achieve this the virtual machine design has local variable support. The tokens can then be back end interpreted, or translated to a Forth system. The translater can be written in high level Forth, and is largely portable, except for the target architecture sections. These are not shareware tools, and were written to support a portable binary system. 5.2. Where can I find a Forth-to-C compiler? An unsupported prototype Forth-to-C compiler is available at . It is described in the EuroForth'94 paper . Another Forth-to-C compiler is supplied with Rob Chapman's Timbre system. 5.3. RECORDS in Forth? Many packages for data structuring facilities like Pascal's RECORDs and C's structs have been posted. E.g., the structures of the Forth Scientific Library ( ) or the structures supplied with Gforth . 5.4. Why does THEN finish an IF structure? Some people find the way THEN is used in Forth unnatural, others do not. According to Webster's New Encyclopedic Dictionary, then" (adv.) has the following meanings: 2b: following next after in order ... 3d: as a necessary consequence (if you were there, then you saw them). Forth's THEN has the meaning 2b, whereas THEN in Pascal and other pro- gramming languages has the meaning 3d. If you don't like to use THEN in this way, you can easily define ENDIF as a replacement: ______________________________________________________________________ : ENDIF POSTPONE THEN ; IMMEDIATE ______________________________________________________________________