I offer an answer to the unspoken question: "Why, oh my goodness, Forth?" I use Forth to program my 8-bit computer SC126, running the CP/M 3 operating system with the ZPM3 extension.
is one of the well-known and popular features of Forth. A program is not a single block of code, but we have access to individual procedures that we can test in isolation, and using the stack allows to enter and control the input and output of each procedure (word).
Sometimes slightly derogatorily is Forth refered as "essentially an assembler". This is mainly due to the fact that, apart from numeric variables and constants, Forth does not have any other predefined data structures. Forth works directly with memory, but it contains enough tools for creating your own data structures tailored to the given problem. Are you missing array of structures? You can quickly add array and structure definitions according to your needs, and if you save the definitions into libraries, you will have a comfort comparable to other languages (and the definitions will only take up space if they are necessary).
You probably won't find this anywhere else. Forth is one big construction kit allows to define your own control structures. For example, the standard CASE..OF statement works only with numbers, but if it needs CASE..OF working with strings, it's simply to define this.
In Forth, the source texts are processed by a so-called external interpreter and the translation is started with the well-known word ":" (colon). This means that between the compilations of individual words, we have the all features of the language at our disposal. So, in addition to conditional compilation of parts of the program, we can perform tricks that are not seen elsewhere. For example, there is a small extension that allows to insert a breakpoint into the program that interrupts code execution. Then can be read the variables or contents of memory, change them or even define new words.
For each word (procedure), there is an address in memory with this word can be indirectly executed . So we can create an address array and easily implement what we would classically need a large and relatively slow CASE type structure for. We can also pass addresses of words to be executed (i.e. function as parameter) or use DEFER-type words, whose function can be changed dynamically during program execution.
Although Forth fans sometimes compare program text to an English sentence, in reality, program writing in Forth is quite difficult to read compared to other languages (Pascal, Java, C). This is also compounded by the (bad) habit apparently inherited from writing in the original "screens", writing shorter words on one line. To improve readability, it is essential to have some formatting rules when writing. In my opinion, very reasonable rules are given in the paper S. Pelc Programming Forth, where the author's many years of practical experience can be seen.
Dirty programming tricks are sometimes used in Forth, faster and smaller than conventional solutions, but these should always be commented.
Programs in Forth are a kind of hybrid between compiled and interpreted text, but compared to classic compilers (C, Turbo Pascal, not to mention assembler), the resulting code is noticeably slower. However, the speed is mostly satisfactory, and time-critical parts can be written in assembler.
One of the features of Forth is its relatively simple implementation. There are a number of different more or less complete attempts on the Internet, mostly from the 70s and 80s, but which cannot be used for serious work. In contrast, DX-Forth is a full-fledged language and development environment that can be used for creating programs without any problems. DX-Forth is Rolls-Royce among CP/M Forthes.
The Forth 94 standard (ANS Forth) was a turning point in the development of Forth, which significantly advanced the language and unified it. DX-Forth more or less follows it, and expands it with a number of useful improvements.
The basic version of DX-Forth traditionally works only with integer arithmetic (which is suitable for most uses), but if you need it, a slightly larger version with floating-point arithmetic is also available, equipped with a set of mathematical functions.
is a given in modern languages, but under the CP/M operating system, DX-Forth is the only language that I know of that allows the use of exceptions.
DX-Forth has a unique possibility: we can define our own words or remove parts that we do not intend to use (e.g. assembler or auxiliary words) and save the modified system to disk. We can then work with the system that we have customized. I have installed my own MAKER extension, which allows to use an external editor (excellent ZDE) and has other improvements.
Another excellent feature is the possibility of creating a standalone program, which does not include word headers and system words unnecessary for the program to run. This creates a COM file with a size comparable to Turbo Pascal or HI-TECH C compilers.
When programming 8-bit computers, sooner or later we will encounter the need to write some routine in machine code, whether for speed or calling subroutines in ROM, etc. The built-in assembler is very easy to use, no linking of external modules or writing raw machine code (Turbo Pascal). The only unusual thing (for me) is the use of the extended i8080 mnemonics instead of the familiar Z80 mnemonics.
The cooperation of both the system and the resulting programs with the terminal takes place through the installation (compatible with Turbo Pascal). We have standard words available for highlighting text, clearing the screen or positioning the cursor. When distributing the resulting programs, we just pack the supplied installation program and the user can use any terminal.
can be in classic "screens" or standard text files with the .F extension, their processing is standard according to the Forth 94 standard.
If we use the Z-System extension, the word ZENV is the key to its use. Z-System is also respected when saving the system or the resulting programs.