- I disregarded much conventional wisdom in order to include exactly the capabilities needed by a productive programmer. The most important of these is the ability to add whatever capabilities later become necessary.
- One principle that guided the evolution of Forth, and continues to guide its application, is blunty: Keep it simple.
- Simplicity provides confidence, reliability, compactness, and speed.
- Forth is a very unusual language. It violates many cardinal rules of programming.
- Actually a computer language should not be difficult to understand. Its purpose is simply to serve as a convenient compromise for communication between a person and a computer.
- A high-level language looks the same to a programmer regardless of which make or model of computer it’s running on.
- A language should be designed for the convenience of its human users, but at the same time for compatibility with the operation of the computer.
- Forth begins with a powerful set of standard commands, then provides the mechanism by which you can define your own commands.
- The structural process of building definitions upon previous definitions is Forth’s equivalent of high-level coding.
- Forth offers a simple means to maximize a processor’s efficiency.
- In Forth, a defined command is called a “word”.
- The ability to define a word in terms of other words is called “extensibility”.
- Extensibility leads to a style of programming that is extremely simple, naturally well organized, and as powerful as you want it to be.
- One of Forth’s many unique features is that it lets you “execute” a word by simply naming the word.
- Forth is called an “interactive” language because it carries out your commands the instant that you enter them.
- Words must be separated by at least one space for Forth to be able to recognize them as words and/or numbers.
- A Forth application, when listed, consists of a series of increasingly powerful definitions rather than a sequence of instructions to be executed in order.
- Each word and its definition are entered into Forth’s “dictionary”.
- In general, computers perform their operations by breaking everything they do not ridiculously tiny pieces of information and ridiculously easy things to do.
- Forth uses “postfix” notation rather than “infix” notation so that all words which “need” numbers can get them from the stack.
- When all operators are defined to work on the values that are already on the stack, interaction between many operations remains simple even when the program gets complex.
- In general, the only accessible value at any given time is the top value.
- To convert to postfix, simply move the operator to the end of the expression.
- The word SWAP is defined to switch the order of the top two stack items.
- When writing equations in Forth, it’s best to “factor them out” first.
- You can define the same word more than once in different ways--only the most recent definition will be executed.
- The word FORGET looks up a given word in the dictionary and, in effect, removes it from the dictionary along with anything you may have defined since that word.
- Only the compiled form of your definition is saved in the dictionary.
- All Forth systems use disk memory.
- The compiler compiles all dictionary entries into computer memory so that the definitions will be quickly accessible.
- Disk memory is divided into units called “blocks”. Each block holds 1024 characters of source, or binary data, traditionally organized as 16 lines of 64 characters.
- The words that follow IF are executed if the condition is true. The words that follow THEN are always executed.
- The words 0=, 0< and 0> expect only one value on the stack. The value is compared with zero.
- Forth allows you to provide an alternate phrase in an IF statement with the word ELSE.
- IF will take any non-zero value to mean true.
- All comparison operators return well formed flags.
- As your applications become more sophisticated, you will be able to write statements in Forth that look like postfix English and are very easy to read.
- The parameter stack holds parameters (or “arguments”) that are being passed from word to word.
- The return stack, however, holds any number of “pointers” which the Forth system uses to make its merry way through the maze of words that are executing other words.
- “Floating point representation” is a way to store numbers in computer memory using a form of scientific notation.
- You should note carefully that when a processor supports hardware floating-point, it is almost always much faster and more compact than the fixed-point equivalent.
- It turns out that you can approximate nearly any constant by many different pairs of integers, all numbers less than 32768, with an error less than 10^-8.
- The user may keep values on the return stack temporarily, under certain circumstances.
- Conditional branching is one of the things that make computers as useful as they are.
- The ability to perform loops is probably one of the most significant things that make computers as powerful as they are.
- LEAVE causes the loop to end immediately.
- This bizarre-seeming method for representing negative values makes it possible for the computer to use the same procedures for subtraction as well as addition.
- The stack can be used to hold either signed or unsigned numbers. Whether a binary value is interpreted as signed or unsigned depends on the operators that you apply to it.
- In Forth, variables are appropriate for any value that is used inside a definition that may need to change at any time after the definition has already been compiled.
- One use for constants is to name a hardware address.
- Forth programmers tend to follow this convention: when possible, words should destroy their own parameters.
- In general, it’s better to put DUP inside the “calling definition” then the “called” definition.
- Forth systems provide ways to manage the dictionary by organizing words into vocabularies.
- Execution of a definition will stop when KEY is encountered until an input character is received.
- Programming in Forth is more of an “art” than programming in any other language.
20190201
Starting Forth by Leo Brodie
Labels:
books
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment