Limits of Forth

In contrast to the public assumption Forth is not so powerful like it looks like. For describing the weakness in Forth it helps to observe projects which are dedicated to the idea of writing a operating system in Forth. I’ve found as a good example, the project is called “Forth OS”. The feature list shows everything, what Forth usually not have and which was implemented in the Forth OS:

– Floating points

– harddrive access

– graphics support

– Multitasking

– USB access

– Audio output

The Forth OS project is great. The user can easily draw a line on the screen and he can even start many programs at once. But, all the feature are implemented in sourcecode. For getting access to it, the Forth OS software has to be downloaded first, which is arround 1.4 MB in size and consists of many assembly programs. It contradicts the story of Forth as small and beautiful language, instead the user get a MenuetOS like bloatware system. And it is very likely that future iteration of the Forth OS project will increase the filesize further. So perhaps in 2 years, the occupied discspace will around 3 MB.

Let us compare Forth OS with a normal Forth. But what is a normal Forth? Perhaps retroforth, gforth or VFX Forth? In reality, most Forth projects are more than only a two stack machine, they can be classified as operating system with an integrated language. Where is the difference between Forth and a mini-operating-system written in C? I don’t know, but let us investigate a minimalistic Forth. Has this incarnation a multitasking feature or high-resolution graphics? No, it hasn’t. That is the reason why the Forth OS project was founded, to extend Forth with needed features.

I’m not sure what this can tell us about Forth in general, but it seems that a minimalistic Zen like Forth works only in theory, if no real computer is used. In reality, most Forth users are using Forth together with an existing operating system, they are installing VFX Forth like mega-IDEs or they are writing a Forth OS like the above cited project.

Let us investigate the sourcecode in detail. The Forth OS project has around 200 kb Assembly written code for the graphics, multitasking, usb and all the other features. In the comment, such a system is called “Forth”, but in reality it is a more an operating system written in Assembly which has an integrated Forth scripting language. The first question is, has the maintainer of the project done something wrong? I don’t think so. The code looks efficient and it works great. I do not see how to make the same feature with less sourcecode.

It seems, that a demand for many features results into a huge operating system. That is not only the case for Forth but for other projects too. I think, the problem is something else. In the description what Forth is, usually a minimalistic stackmachine is described which can be iimplemented in around 2 kb ROM on tiny computers. But I have doubt, that such a Forth is useful in reality. Real Forth projects like gforth, Forth OS and VFX have more features than only dup and +. And as a consequence the occupied discspace is much higher. I would guess, that a good forth project which is doing something useful is nearly the same like a C programming project for programming an operating system. That means, between C and forth is no difference, except that C programmers know from the beginning that their system is bloatware and needs a register-machine.

Let us describe the vision behind Forth. The idea of Chuck Moore was to program tiny software, which is not more than 500 bytes. And indeed it is possible to write Forth code in that size. But the same is true for assembly, Brainfuck or C. If the aim is to program real application, than Forth has no advantage. That means it uses 1 MB or more like a mainstream programming language.

Is it fair to describe Forth as a stack-based programming language? It think this description is wrong. A stack-based programming langauge is something which is teached in computer courses at the university. They are based on a theoretical computer, called pushdown automaton with two stacks which is indeed very simple and elegant. But realizing this machine in reality is not possible. An Forth operating system for beginners is around 1 MB in size, a professional Forth IDE has around 10 MB. And in most cases such systems doesn’t even run on Forth CPUs but they need Intel x86 machines.

The misconception is, that the newbee has the hope that he can program a minimalistic Forth CPU with no operating system in Forth, only with the language itself and this result into high effiencient code. This assumption is not practical. In reality, there are not Forth languages but only Forth operating systems. That are projects like the retroforth, gforth or eforth.

Let us take a look on other Forth implementations, They are usuually 500 kb in size. Is that a mistake, are the Forth environments in reality much smaller and most of the sourcecode is only documentation? No, the only thing what is wrong is the comparison between reality and vision. The vision of Forth is, that it something which is not bigger than 1 kb or maximal 2 kb with addons. The reality is, that existing Forth projects are similar to operating systems. They are mostly written in assembly language and after booting them on a pc or on a microcontroller a Forth like language is only used as a userinterface, like the UNIX shell.

Let us compare Forth with Unix. Is Unix equal to the bourne shell? Consists Unix of pipes which are connected together and for loops for iterating? No, it is only the shell. Unix in reality is an operating system which is at least 200 kb or in newer versions much more bigger. .And the same is true for Forth. A real Forth like the bigforth project consists of around 50 MB sourcecode. Forth as a userinterface and shell is only a small part of it.

Let us take a look into Wikipedia what the definition of a shell is. A shell is a command line interpreter for executing external programs. For example, somebody can call the grep tool, or the df program. A shell without external tools is nothing. The combination between shell and programs is called operating system. Now let us take a look into the definition of Forth. The mainstream definition of Forth is, that is a concative stack-based programming language. This definition is wrong. Forth is only the commandline interpreter in a much bigger Forth operating system which consists of a multitasker, graphics interface and harddrive driver.

Let us describe what we can do with the Forth language itself. If it is executed under a normal operating system, the Forth language can access existing C routines. If the Forth interpreter is executed inside an Forth operating system it can execute code written there. But, if the Forth language is run alone without an operating system it can execute nothing. What the user can do, is extend a bare-metal forth to an operating system, but he will end with an operating system too which is around 1 MB in size and contains subroutines for graphics, harddrive and GUI.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s