Why Forth is cool

The best way in understanding Forth is to think about programming a virtual machine interpreter. A virtual machine can be realized in many way. Such a system is needed if somebody want’s to parse a computer language. Usually the VM provides some commands like print, goto, for and if. The VM takes a program and executes it. Before it’s possible doing so, the VM needs some helper variables, notably an instruction pointer for referencing the current position in the program and a registerset for storing call-back adreses and loop variables. The funny thing is, that in most cases a VM is constructed according to the Forth principle or at least it will be very similar to Forth. That means, the VM provides the following elements:

– opcodes which can be called from the outside

– instruction pointer

– datastack, returnstack

The VM interpreter gets the sourcecode and executes the commands in linear order. After an iteration the instruction pointer is increased. If a jump to a subfucntion is needed, the callback address is stored in the stack. That means, a minimal Virtual Machine interpreter is equal to a Forth system.

The open question is, what useful things can be done with such a Virtual machine. The answer is, that at the same time a VM is a powerful concept but it’s also a trivial concept. A VM itself isn’t solving a problem but is creating a problem. Suppose, we have create a VM for executing language. The follow up problem will be to construct the hardware for executing the VM. WIthout a computer, a VM can’t be executed. But also from a software side a VM creates many new open problems. Suppose we have a VM which can handle a small program. What should be included in the program, which subfunctions are needed? This question remains also open, the VM itself can’t answer it.

Virtual machine interpreters in general and Forth in detail are not an answer to a problem, they are the question mark. The reason why both is fascinating has to do, that it’s unclear what somebody can do with it. A VM is comparable with a C++ compiler. It’s possible to create anything or nothing with it. It possible to write an operating system, a game or whatever. The difference between a C++ compiler and Forth is, that Forth provides this problem more direct. That means, if somebody is writing a small VM in 100 lines of code the team will have lots of trouble. Because he asks for the hardware, he asks for software, for algorithm and so on.

Libraries

The main reason why Forth is ignored by Mainstream programmers is because it doesn’t provide answers but new questions. For example, the Linux operating system provides lots of answers. It explains to the user how use the harddrive and how to establish an internet connection. The Python programming language also provides lots of answers. It contains of a powerful library, object-oriented features and variable types which allows to simplify programming. In contrast, Forth doesn’t provide anything. It’s the VM and nothing else. Forth is some kind of computer literacy test, if somebody is able to program the operating system from scratch, and invents the algorithms from scratch. If somebody is not familiar with computers he will be lost at Forth.

What we can say about Forth for sure is, that it’s some kind of virtual machine definition. Any Forth contains of opcodes, instruction pointer and a stack for the return address. A virtual machine is needed if a computer language should be executed. It’s not possible to run a program without a virtual machine.

Almost Forth

It’s possible to create a virtual machine interpreter which isn’t Forth. The addition is to replace the stack with registers, everything else remains the same. And voila, it can’t be longer called a Forth system. The funny thing is, that the performance of such a VM remains the same, only minor differences are there. Also the programming of a register based VM looks very similar to a stackbased version. Let us give an example. A stackbased Virtual machine would provide an opcode like:

4 5 add

The result will be 9, because both numbers are put onto the stack and the add operator gets executed. Now the add opcode in a registerbased virtual machine:

add(4,5)

The syntax of the opcode looks more like the C programming language. Like in the stackbased example, it’s possible to give the function a parameter, but this time the parameter have a certain type. Parsing register-based opcodes is a bit more complicated. That means, the parser is written in more lines of code. In exchange, the programmer will have less trouble in daily use, because the syntax looks similar to Python and C syntax. In another example the difference becomes more clear. Suppose, we want to give a parameter to an opcode which isn’t a number but an array. In a minimalistic stackbased virtual machine, the opcode would like this:

$1000 5 print

The Virtual machine parser will read the stack and interprets the first parameter as the starting point of the string, then comes the length and last the opcode. After executing the command the string is put to the screen. And now the print opcode in a register based virtual machine which isn’t Forth:

print “hallo”

This statement looks similar to the Python syntax. It’s easier to write for the beginner programmer but harder to parse by the virtual machine. Writing a VM which is able to execute the second command is a harder task. It’s possible but the number of codelines is bigger. The reason, why C and not Forth is the dominant programming language has to do with that most programmer like the second syntax more.

What we can say for sure, is that the “print ‘hello’” statement is not allowed in Forth. There are two reasons against it. First, the print command has to be at last and not at first, otherwise the parser is not able to execute the correct opcode, and secondly is not allowed to put a string to the stack. Instead the pointer to the string must be put on the stack. Both constraints can’t be made undone by better programming, they are built into Forth. The only way to bypass the bottleneck is to use a different kind of Virtual machine interpreter. For example, a register based VM which has a more elaborated parser which can handle strings as well.

According to the self-definition of Forth the language is extreme flexible because of the absence of any standard. In reality, there is a standard, called minimalism. This principle forbids, that somebody extends Forth with libraries, creates new libraries or writes a different kind of parser. I want to give an example. In theory it’s possible to transform a stackbased VM into one which can parse the “print ‘hello’” statement, so that the programmer doesn’t have to change his programming style. The reason is, that in Forth any program can be created, so it’s possible to create in Forth a python interpreter too. This will work like a normal python interpreter. But in reality, no such a project was done in the past, because the result will not look like Forth anymore, but like Python. The same problem is there for object-oriented extensions to the Forth language. There are many of them available which allows to program the sourcecode in OOP style. But, in reality, nobody is using mini-oop.fs and similar extension because it violates the standard, that no standard is allowed.

The Forth rule can be explained with minimalism, that means anything is allowed which reduces complexity, but anything is forbidden which increases complexity. The open question is, what can be done with Forth if everything what will make life easier is forbidden? The answer to the question is given by the Forth community. They are exploring things inside the Forth standard, which looks very esoteric, but it make sense from a certain point of view.

Advertisements

How to create a Forth standard

Update 2018-11-18
Poll is over, “How to create a Forth standard” has won with one vote. Here comes the text.

The official Forth-200x standard is out there and is a 300 pages pdf documents which contains some basic words. The problem is, that nobody in the Forth community accept this standards, and attempts to pushing it in the world will fail. On the other hand it would make sense to support Forth but how can this be done without a standard?

The answer to the problem is not the technology itself, but the ecosystem of programmers around it. Let us go into the details. The MenuetOS project is a good example for a working gui which is not Linux. MenuetOS was programmed in assembly which is similar to Forth, but not so powerful. The more important question is not the MenuetOS kernel itself, but the number of people who are writing software for it. What would happen if somebody is reprogramming MenuetOS in Forth? At first, it is a great idea because the same code will run on other architectures than only x86. But this newly developed project will fail if the number of people who are contributing code is too low.

The main advantage of Linux and the C programming language is, that many thousands (or millions) programmers are there who are familiar with the ecosystem. In case of Forth this is not the case. That means, on the first hand we have a stackbased programming language which is great for software development and uses existing hardware efficient and on the other side nobody is interested in Forth. To bridge this gap modern tutorials are needed. The problem with Forth is, that nobody is able to explain it to the masses. The tutorials about Forth are bad written and most are outdated. And if nobody is teached in programming Forth he is not able to write sourcecode from scratch.

The first step in establishing a Forth Standard and a Forth operating system is to write a book about Forth which is easy to read and explain the basics to the newbies. Animating somebody to write Forth code is equal to teach him the Forth language. The easiest way in do doing so is to explain Forth as an advanced assembly language. An appropriate book title would be “From x86 assembly to Forth”. That means, the requirements in learning Forth are average assembly skills and with that background knowledge it is possible to explain how to use this skills in a Forth environment.

Let us take a closer lock to Assembly language. The main advantage of assembly language is, that it is a minimal language. An assembly program can be executed without an operating system. It communicates on the hardware level with the cpu. One of the reasons, why Forth was used in the 1980s more often but since the 2000s seldom has to do with the changed status of Asembly programming. In the 1980s it was common to program in Assembly. For the Commodore 64 it was the mainstream language, but many MS-DOS programs in that days were created as well in machine code. Another similarity between Forth and Assembly is, that both languages are compact. That means a typical program has not more than 2 kb in size. Such a program can be called a huge project which takes many weeks to program it.

If somebody wants to bring Forth forward, he has to connect to this programming style. If somebody doesn’t want to learn assembly or someone argues, that a hello world program needs 2 MB in size, he is not ready for Forth.

Forth tutorials

The demand for better Forth tutorials is easy to formulate but how exactly would such a book look like? The problem in modern computing environment is, that even the Assembly language is hard to teach. The current standard book about AMD64 assembly programming is not a single volume but a series of 6 books with each 700 pages. And that is only the reference manual for the opcodes, if somebody needs more detailed explanation how to code a hello world example and assemble it into binary code he needs additional material. Even our fictional user has read all the information, he is only able to write assembly language but he has not written a single line in Forth. Then he will need more books.

The Forth community itself has recognized this problem and as a counter reaction they have invented new cpu chipsets with a smaller amount of commands. The novix cpu is a famous example but also the modern GA144 chipset is compared to the AMD64 a small device. The problem is, that these architectures are more complicated to understand than the AMD64 chipset, because they are more advanced. If somebody is trying to describe them, he will need the double amount of books and they will much more complicated to read. It seems, that especially a programming language which is simply and especially a cpu with has a low amount of instructions is harder to describe than current one.

Unfortunately, nobody knows how to overcome the problem. What we see in reality is, that 99% of the programmers ignore Forth and write their hello World application in Python, because they don’t want to read so much information and they have no need for a lightweight cpu. That means, the number of Forth programmers today is smaller than in the 1980s and the prediction is negative.

Let us take a look how complexity is handled in the C programming ecosystem. There we have many layers which are put on top of each other. The layers are called microcode, firmware, bootlooder, operating system, GUI, system library, device drivers, compilers, programming langauges and more programming languages which are using languages below them (Python is an example for that). That means, it is a mess. And Forth programmers are right if they are calling the C / Linux ecosystem outdated.

The problem is not Forth itself, the problem is, that the average programmers would not renounce on a single layer. For example, suppose somebody programs software in Python. And we want to convince him, that Python is inefficient and that C is the better language. That means, he can write the same code direct in C and it would compile to much faster code. He could save one layer in his workflow. The answer is, that he doesn’t like C. That means, he wants to use Python and he will ignore the additional layer. Now suppose we want to teach the programmer not only to avoid Python, but also C, also the operating system. What would he say? He will not love it. That means, the programmer is trained in a certain style which has to do with additional layers, but not with slim programming.

What Forth wants from the programmer is to forget all the layers. And not using Python, not using C, not using Linux, not using x86, not using GCC, not using register machine and instead rethink programming at all. How many people like this? Not very much.

Forth on Brainf***

The most simple Computer isn’t the MOS 6502 CPU but a turing machine, better known as Brainf*** computing model. It contains of a tape, a read/write head and simple left/right commands. The commands are the assembly language of the computer. They fit on a single DIN A4 paper which makes things more easier to grasp. But from a certain point of view, a Brainf*** computer is much harder to program than an AMD64 chipset. Because sometimes small is more complicated.

With Forth the programming can be improved. All what we need is an Forth interpreter on top of the Brainf**** computer, and now we can enter a Forth For loop and this gets executed on the Brainf*** cpu. Without any compiler in between. Sure, the Forth Interpreter works as an interpreter, but he needs not much space.

This flexibility of Forth is the reason, why the language is so fascinating. Any device which is turing ready can run Forth. And there is no such thing than something below Forth.

But if Forth is so great, why are using only a few people this powerful language? Doesn’t they know what the advantage is? Oh they know Forth, but they can’t handle it. They find it easier to design chips with many registers, and they like it more to program in C++ but not in Forth. The funny thing is, that they even prefer to write a software which has 1 million lines of code instead the same software in Forth which needs only 2000 lines of code. A possible explanation was given in the previous chapter. It is the same reason why people are prefering Python over plain C, even a compiler generates better code. What mainstream programmers want is as much layer they can get. They do not want to program on bare metal they want to write in a python like style.

Python is a good example for what is wrong with modern computing. According most benchmarks, Python is 20x slower than C. Their object-oriented features are not better than C++, and the Python virtual machine is compared to Java not very well. That means, from a technical point of view, Python is bad programming language. But the people love it. All the beginner worldwide are learning Python, but not c, not C++ and not Java. Are these guys wrong? Yes they are. Python programmers didn’t have understand what a C++ compiler is about. And they are proud of it. Instead of arguing with C++ guys about the better programming langauge, the Python fanboys have build their own world. And it is likely that the Python community will grow in the future. That means, the Python programmers are different from C++ programmers.

And the same game is played with Forth. The opposite is, that Forth is ignored by much more people. Java programmers hate Forth, Python programmers hate Forth, C++ programmers hate Forth, even Assembly experts hate Forth. If somebody want’s to stay alone in front of a computer, than Forth is the gold standard. He can be sure, that nobody else want to see his code, especially if the code was written for a special Forth dialect created from scratch, like Colorforth.

This brings us to the question: what is the advantage of programming alone and without a huge community? It’s the same question like why somebody walks alone through the snow and climbs a mountain. The hope is to explore something new. And Forth is something which is new. Colorforth for example was the first minimalistic Forth ever invented. It should be put in a museum and teached to future generations.

About which kind of technology the Forth community is talking?

For the newbies it is very hard to understand what Forth is about. They see only a programming language which is hard to master but they don’t recognize the advantage. So what is Forth, if we want to define it in colloquial terms?

The software side is comparable to projects like MenuetOS and ContikiOS. Both are example for small scale operating system which needs less then 2 MB on the harddrive but provide a full featured TCP/IP stack, a webbrowser and a GUI. MenuetOS was programmed in Assembly language while Contiki was programmed in C. But it is possible to reprogram the software in Forth. The result is a very tiny fast booting operating system which is able to do everything what a Linux OS provides.

The second aspect of Forth is the hardware. Running Forth software on normal x86 cpus doesn’t make much sense. The idea is to create a different kind of processor which needs less gates, consumes less energy and is cheaper. Now we have a basic understanding what Forth is: we are taking a cheap CPU, put a small operating system on top of it and get a computer which is superior to today’s mainstream computers.

That is the general idea behind Forth. And most discussions and Forth related talks are about certain aspects of this vision. A more mainstream compatible but not Forth related approach would be to stay within well known c programming language and create an operating system which takes less memory. The ContikiOS was mentioned above, it is so small that it can run even on the Commodore 64. The idea is to minimize the footprint of the software. That means, everything which goes into the direction of creating an operating system in under 100 kb is great, while normal Linux compatible operating systems which takes 500 MB RAM only for booting the terminal is the wrong way.

With the C programming language it is possible to program small kind of software. But if the idea is to reduce the footprint further a switch to the Forth language is necessary. The reason is, that a C compiler is a huge piece of software and it won’t run for example not on the Commodore 64. That means, the ContikiOS needs a crosscompiler. Forth can help to bypass this problem.

It remains the question open if its make sense to create ultra efficient hardware / software. Why do we need an operating system which takes only 100 kb? This is indeed a bottleneck, because this kind of software is hard to program. It is additional work which has to be done. And it is possible to argue against such kind of projects. This is the reason why Contiki, Forth and similar projects are called a niche project. They have not encouraged a large group of programmers.

If nobody press the vote button, a Python random generator gets started.

import random
class Randomgenerator:
  def __init__(self):
    print random.randint(0, 2)

main = Randomgenerator()

The Mark I Forth homebrew CPU

Update 2018-11-03

In Europe, 8-bit-homecomputers like the Commodore 64 are very popular until now. There are lots of forum in which the amateurs are discussing each aspect of the machine. It is possible to criticize this behavior from two sides. The first one is from the mainstream perspective. Why is somebody playing around with the 6502 cpu, if he can buy a normal Windows PC with 4 gb RAM for small amount of money in each computer store? Isn’t it waste of time to program assembly code on the Commodore 64?

This critique doesn’t make much sense, because the amateurs are doing so, because they want to learn something about the machine. There is a second option to criticize the 8-bit community. Why are they playing with a machine which was fabricated by Commodore if they can design their own homebrew CPU? A short look into the so called homebrew scene shows, that the 8-bit CPU is well known, but the amateurs are going a step further and are trying to build a computer from scratch. A starting point might be a 4-bit cpu which is build from relais, and a second choice is to build a stackmachine, aka a Forth CPU, http://www.aholme.co.uk/Mk1/Architecture.htm

The MARK I Forth CPU is perhaps the most famous example. It is remarkable to read the project description: quote: “the Mark 1 took a month to design, 4 months to build and a month to program”. The project itself is not very complicated. Some TTL chips and a bit experience with cpu design are enough and the machine is running.

What I’m interested in is the programming part of such a machine. The reason why has to do that repeating the hardware design is easy. Anybody can build a Mark I clone, and at least one guy have done so in the year 2006. But, building the hardware alone doesn’t make much sense. With sourcecode, the hardware will do nothing. What I’m interested in is to know how to program the software in Forth.

According to my investigation this is the real bottleneck. Tutorials about programming are focused on the C programming language. The idea is to first build a c compiler like “Small C”. Create with that compiler a Minix like operating system and than all the other stuff on top. But, can this bootstrap process be repeated with Forth too? This is unclear right now.

Let us watch the Mark I CPU hardware again. The layout is given on the website. It contains of an ALU, memory, registers and a stack. The layout is more complicated than a simple half-adder but for FPGA experts and hardware developers in the industry it is easy to understand. That means, there is no real problem available.

The only problem I can see is, if the hardware is running well but the sourcecode is missing. How can be an operating system created with Forth? This is unclear.

IO ports

Some Forth experts told me that after the hardware is running it is necessary to control the I/O ports. https://wiki.osdev.org/I/O_Ports Possible devices at the io ports are: DMA controller, interrupt controller, floppy disc and serial port.

Another hint was that out of the box Forth systems like: DXForth http://dxforth.mirrors.minimaltype.com/, Camel Forth http://www.camelforth.com/ and SL5 The Stackworks Forth, http://www.softsector.aplaholm.se/cpm/sl5/ are the right choice.

more Forth related cpu: https://github.com/ForthHub/ForthFreak/blob/master/ForthCPUs (most of the links are only available with Archive.org)

Software programming

Writing software for the MARK I computer is a bit complicated. Only Forth programs runs on the system, it is not possible to compile existing C sourcecode for a stackmachine. The reason is, that the MARK I Cpu is not compiler friendly, that means, the system has to few register so that standard C compilers like GCC will not work.

And without the ability to generate from C sourcecode, binary code it is not possible to run Linux on the system and without Linux it is not possible to run higher-applications and tetris-like game. So what can the programmer do? Right, he has invent something which is better than a C compiler. He must program everything from scratch in Forth. But isn’t it very complicated to write an operating system and high level application from scratch? At first it is important to determine how man lines of code an operating system needs. Because software projects are calculated in man years and a single programmer can produce not more than 10 lines of code per day. The Linux kernel contains around 40 million lines of code, and the gnome GUI environment is much bigger. It is not possible to create such a large codebase from scratch by a single person. But what is possible is to write a small compact operating system.

A famous example is MenuetOS https://en.wikipedia.org/wiki/MenuetOS which needs less than 2 MB on the floppy disc. It was programmed in assembly language, has a TCP/IP stack and a GUI. Assembly language is very similar to what Forth is. According to the ANS Forth standard it is possible to run Assembly code inside a Forth program. This allows to write hardware independent code. So what the programmer has to do, is to write MenuetOS in Forth and put only a small fraction of the code in assembly-language brackets. In case of the Mark I Forth CPU he will not to write anything in assembly because Forth is the assembly, but perhaps the same code should run on the Commodore 64 too, so it is better to hold things separate.

How long does it take to rewrite the MenuetOS in Forth? I don’t know, a real life example is available which is called the iTV project (developed by Chuck Moore). It was a hardware / software combination for a multimedia PC. The iTV PC was simply a computer which runs a MenuetOS like operating system written in Forth. The most important question is: how small can a full featured operating system are Are 2 MB enough for a server grade operating system which is connected to the internet, or are 5 MB needed? If the idea is to write a small os, than Forth is the way to go. That means, it is possible to ignore the Linux ecosystem and write an operating system from scratch which includes the kernel, the GUI, the TCP/IP stack, the sql database and so on,

The possible performance of a Forth OS is comparable to MenuetOS. Because the Forth VM is able to compile the words. This is equal to what the Java VM does: it converts the sourcecode into easy to parse bytecode. The execution speed of bytecode is nearly the same, like the output from a c/c++ compiler. In case of doubt, it will be a bit slower, but in reality not very much. That means, an operating system written in Forth will reach the same speed like the MenuetOS.

The more important aspect isn’t the Forth language itself, but the algorithms. For example, the audio codec OPUS is more efficient than the mp3 audiocodec. Using the right algorithm will improve the overall system speed dramatically.

The bottleneck of Forth is not the language itself, but the amount of documentation which is available. The stackoverflow website has under the tag Forth only 197 questions available, https://stackoverflow.com/questions/tagged/forth That means, if the programmer has a certain problem while his journey to a Forth OS he will be alone. Nobody else had the same problem in the past and he will find no answer in the internet. This will slowdown the development process. For example, if the programmer want’s to know how he can use Forth to control the IO ports of the Mark I Forth CPU, he will find on Stackoverflow no answer. That means, the programmer isn’t able to implement it in sourcecode. From a technical point of view, it is possible, but the programmer doesn’t know how exactly.

Update 2018-10-30
The poll has 4 votes right now. I will let the poll a bit open and start a new one in parallel.

Here is the of the C++ random generator which gets started if no one press the vote button:

#include <iostream>
#include <random>
class Randomgenerator {
public:
  Randomgenerator() {
    srand(time(0));
    auto number=rand()%3; // between 0 and 2
    std::cout<<number<<std::endl;
  }
};
int main() { 
  Randomgenerator mygenerator;
}

Windows and Forth are great companions

The current Windows Server 2016 operating system is the most advanced software ever. It is able to handle E-Mails, Webcontent, network file systems and databases. Together with the enduser OS, Windows 10 it is a great platform for any company. Programming Windows Server 2016 is very easy and can be made with the “VFX Forth” integrated development environment. VFX Forth comes with lots of predefined words which are equal to small subprograms. A word can be “add” and this allows the super-user to add two numbers which are stored on the stack.

VFX Forth is well documented and can be used on large mainframe systems. It is able to utilize the complete amount of RAM and all CPU cores, so the Windows Server will run much faster than with Linux. In general the combination of WIndows Server 2016 plus VFX Forth is the professional answer for today’s need in computing and brings forward the digitization for each company. Forth is able to simplify the software development process and even newbies are able to create their first WIndows App in under 10 minutes. VFX Forth comes with an integrated debugger which makes it easy to trace the data and return stack. It is even possible to create so called turnkey application which are equal to a precompiled binary file. More information are available in the manual https://wiki.forth-ev.de/lib/exe/fetch.php/en:projects:a-start-with-forth:vfxman.pdf

In contrast the traditional combination of Linux plus C++ is outdated. Open Source software which has the GPL license is not the best choice for future oriented companies, and C++ has also major weakness. For example it is difficult to write GUI programs for the GTK+ environment, also the object-oriented feature are too complex. Forth is much easier to use, especially for Windows users. It is the superior programming system which is revolutionizing software development productivity.

Bringing Forth to the desktop

People who have this blog since a while, would recognize that in the subtext the Linux operating system was recommended for programming tasks. Right now, it is the most advanced piece of software I’m aware of it. But perhaps this decision can be improved if we are let the Forth language come in. The question right now is how Forth can be compared with Linux. The main idea behind Linux is, that software is everything and hardware can be ignored. The Linux kernel is implementing a complete operating system from scratch and ignoring existing BIOS drivers which are built-in every PC. But, after booting up a PC the system knows exactly what a network is, what a graphics card is and what a cpu scheduler is, even without booting the Linux kernel. All the information are stored in the BIOS, in the existing ROM chips on the hardware and even on the CPU itself.

Forth is a good choice because Forth is as default lowlevel and bare-bone oriented. That means, a typical Forth program contains of low amount of commands and if a Forth system was programmed right, it will use existing BIOS routines and doesn’t invent his own network system. The main difference between Linux and Forth is, that the Linux OS is documented quite well with lots of tutorial like the famous book of Andrew Tanenbaum, while around Forth there is no information available. Today, I’ve checked out Stackoverflow. Under the tag “Forth” they have under 200 questions right know. This can’t be called a huge community, it is more a niche.

The main idea behind Forth is a better balance between Hardware, software and operating system. Linux has the focus entirely on software, Forth is more hardware oriented. In theory the result is a more efficient overall system, which needs less power consumption and can be programmed easier. The drawback is, that in the now it is very complicated to write an OS in Forth, mainly because nobody has tried so before. The only bigger example is the iTV company of CHuck Moore which has developed a workstation. But the computer isn’t sold anymore and the iTV PC is not available in a computer museum so that nobody can reverse engineer the software.

In theory the famous SVIG (Silicon Valley Forth interest group) has the aim to promote the usage of Forth, but everybody who has read their printed publication or watched one of the youtube streams will recognize that they are doing exactly the same. SVIG doesn’t bring Forth into the mainstream, they make complicated things more complicated. So the problem is: where to start if the aim is to make things more transparent? Right now I see two potential starting points for teaching Forth to a mainstream audience. The first is to simulate a CPU in an electronics simulator. That means, every transistors is visualized and the user can see who 1000 transistors are forming a CPU. The other possibility is a qemu image, which is an operating system written in Forth, compared to the menuet-OS project. The aim is, that the user can boot up the system and run his own Forth software in it. This allows him to interact with the existing BIOS which is emulated by qemu too.

In contrast, I don’t think that existing Forth implementations like gforth or Forth derivatives like Factor are making so much sense. Because it is unclear what the advantage to existing software is. The main advantage of Forth is, that it can replace Linux, so there is a need to bare-bone programming directly on the hardware.

One aspect in Forth is important. The language isn’t faster then C. This might be surprise because most people are interested in efficient computers. But it is in reality not a big problem. The slowdown of Forth compared to a C program is not more then the factor 3. And this amount can be compensated by better hardware. If the aim is to speed up a Forth program, not a better compilation to existing x86 architecture is used, but instead a better CPU can used. For example a memristor which is a combination between DRAM memory and CPU.

A carefully dive into “Forth vs Linux” debate

Linux can be called the most advanced operating system right now. It is hacker friendly, is open source and is used on many servers and as a workstation. Sometimes, Linux is compared with netbsd, FreeBSD or SUN OS, because these systems were used early on workstations, but in general Linux is accepted as superior, mainly because of the size of the community and how fast changes are integrated into the kernel.

But, there is competitor in the shadow, called Forth. In theory, Forth can replace Linux. But it is unclear how exactly. Let us make things more easier and describe what Forth can do for a user in the mainstream. A computer can be booted with qemu, but qemu needs an operating system which is stored in the .img file. Some github projects are available which provide such a qemu image with Forth. The idea is similar to the retroforth project which was programmed for the Commodore 64, but only for the x86 PC.

The assumption which was teached by Linux is, that after the booting, the operating system must provide all the hardware drivers for example network, graphicscard, filesystem and so on. And that without the Linux kernel and the userland no additional program can be started. But is this assumption correct? Every computer has a BIOS as default. The BIOS provides the VESA standard which is able to paint lines on the screen. So in theory it is possible to run a PC without an operating system, or with a very small one, for example QNX which is much more compact than Linux. What if we program in Forth a small operating system which is utilizing existing BIOS routines for getting network access, videographics access and put sound to the speaker?

It is unclear right now, if this is possible but it would bypass the existing Linux ecosystem. It would feel more like the early MS-DOS which contains only the msdos.sys and command.com file, but is programmed in Forth. And thanks Forth no complicated C compiler is needed. So the whole system would be a strip down version of Minix 2.

Suppose, a Forth microkernel is able to start high-level programs and schedule them. Suppose the system fits in under 500 kb and is more efficient than current Linux distributions. What can the user do with such a system, doesn’t he has to write Forth code? Yes, he must. It is not possible to execute Linux binary in Forth, so the user must write all the software from scratch. But, as far as i have seen in the Forth documentation it is able to extend the ANS Forth standard with object oriented features. And writing all the needed software is possible. On the first look, the Forth syntax is a bit complicated, but not more complicated then C++. But the main advantage is, that it will run efficient, especially on low power cpus.

The disadvantage is, that the user will loose most of today’s ecosystem: the Linux operating system, the C/C++ compiler, existing libraries for OpenGL access and most other features created by the Open Source movement like the Ubuntu ideology which has the goal to teach programming to beginners. In contrast, a software ecosystem made of Forth is much more mature. That means, Forth is the language of computer scientists

What is the idea? The idea is to create a compact operating system, which is faster than Linux and takes less resources than Linux..Such an operating system is not programmed in Assembly language like the menuet-os example, but in High-level Forth. That means, in Forth is assembly language integrated for setting the BIOS Vesa mode, but then the user can use Forth high-level commands to put lines on the screen. It is unclear, how to program such a Forth OS, but in theory it would make sense.

The most dominant problem is perhaps, that existing software written in C would no longer run in Forth. It is not possible to convert C sourcecode into Forth. Only the opposite direction is possible, but there is no github with Forth sourcecode available. That means, the project would start from scratch and write everything new. As far as i can see at Stackoverflow and on github, there is no large community available which is interested in such a project. Most programmers are fully stretched with Windows, Mac and Linux, they didn’t see a need for Forth. And the programmers who are familiar with Forth are also not interested because it is to easy for them to write a QNX clone in Forth. It is something which doesn’t bring the Forth movement forward.

Forth is the wrong way, because it makes no problems

Abstract
The Forth programming language is superior to all other computer architects. The programs runs better and the hardware is more efficient. But for teaching purposes this is not a wishful state. Students learn better if the underlying system isn’t working very well. The UNIX operating system produces a lot of trouble, and this is the reason why it is the better teaching tool. Apart from a datastack and a returnstack UNIX has much more to offer, for example a POSIX API and a high level programming language, called C.

Introduction

The paper is copyright protected. That means, it is not allowed to redistribute it over the internet or in Academic social networks. To get access to the fulltext, the user must proof, that he has reasonable knowledge about Artificial Intelligence.

1. Who has invented the perceptron in 1957?
a) Frank Rosenblatt b) Richard Feynman c) Dennis Ritchie

2. Which programming language is used heavily for Aimbot programming?
a) PHP b) LaTeX c) AutoIt

3. Who is the inventor of the git-version control system?
a) Linus Torvalds b) Bill Gates c) Steven M. LaValle

4. What is PDDL?
a) computergame b) operating system c) symbolic planner

5. Who is the inventor of BEAM robotics?
a) Mark Tilden b) Sebastian Thrun c) Marvin Minsky

The passphrase gets formed by the correct answers in the quiz. For example, if the choice is question1=c, question2=a, 3=a, 4=a, 5=b the following bash command in the Linux operating system is used for decrypting the paper:

gpg --passphrase 1c2a3a4a5b paper.txt.asc

Here comes the fulltext of the paper.

-----BEGIN PGP MESSAGE-----

jA0EBwMCt/yqAiX/5hpg0usBCeoqWDPKD9iMpOIxDIeUpMpRQVSGB+j8whtYLCOq
8w+dukdWBnSL2an5x9kbUtR5my1KAKXA/dJvnEZ5Jt3Sb8TbPYICea9m+pGWySlX
7nwyiOt7mBV1XCg1GfTV7IrmA9ky7ULlen+hZo+syCr/+NMJ0sQ/lfAAqBTDulsR
/Jd7GdFQ5qDVzlcYYoQwCTEB+3PyaZl2uUMGWMtKPsi4pA4TvyeOrAP4cbHdxand
bYgOVQIRGWQnFfJ4mho9VIi4ZJF+KVMBI3uQegogKekDJnBkYvznbQg+jMbExXpa
doGAU50cG1CEx+TQP1V9vwICqWWya5RNIUzCNfWtU+LS8N6/vfIp+kCODoJFNLPY
3s0f+4VnLTSXJjPqbkdtjLFA8wJ1srwKczj2bn362WWjrhJQ8XBWJqHR2cqfkHdi
RxPRx9sz0Amw7rRIdzFKi86wOL/f2Gz0Qn1QbYNjnYzHn5atq4dpFqzoza8LZQxu
RCt6YDa5AfgMU/DVwDZj8ku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