Pygmy Forth on the Pi

In 1992, I lived in North Vancouver. I originally moved out there for a Smalltalk job, which never actually happened. I just couldn’t move back to Toronto before spending at least a year in Beautiful British Columbia (license plate tagline). I spent many wonderful hours exploring the city to the south and the mountains to the north.

This was a time of extensive miniaturization in the personal computer realm, with many new powerful and inexpensive laptop computers arriving on the scene. PC expansion cards and microcontrollers were also a big thing at the time, and I did some consulting and contracting in all these areas. Of course, my experiments and exploration usually centred around Forth. I envisioned a ‘Silicon Garden’ machine with many independent yet interconnected Forth processors. It would carry me back to the ‘unfettered fields’ of AI that I roamed in the 1980s. This journey would culminate ten years later withpicoXpert. To this end, I embarked on the crafting of my own Forth to be used for custom development. Most serious Forthers eventually feel the urge to design a version of their own, and Forth happily obliges with its easy, open, and flexible nature. I wanted a simple system, probably not much more advanced than Forth-79, that would allow for syntonic wandering and invention.

After looking around at the many Forths available (the language was already over 20 years old), I found that I liked one better than all the rest: Pygmy Forth. One of the true pioneers of truly useful Forth stuff is Frank Sergeant. He created a wonderful small Forth many years ago, called Pygmy, that had a tiny kernel written in 8086 assembly language and a bootstrapped Forth in Forth that could be modified and then ‘regenerated’ as a new system. It was a 16-bit Forth, derived from Charles Moore’s cmForth; you don’t get a better pedigree than that. These and other treasures are available and described on his web site.

One of those treasures is a newer (2017) version of Pygmy, with a kernel written in Python. The Forth in Forth system is then loaded on top of the kernel, similar to the bootstrapping mechanism of the original Pygmy. This new version (32/64-bit) has several key benefits. First, since the 8086 code is now replaced by Python, it can run on virtually any target system, including the myriad of single board computers (SBC) so popular today, such as the Raspberry Pi. All that’s required is a Python 3 interpreter, which is very common in most modern systems. Code words are written in native Python, opening up the possibility of extensive access to the underlying operating system and third party libraries via Python. Second, it supports plain text files for source, in addition to the venerable blocks (screens) of ye olde Forth. This was one of the major additions I implemented on my own version back in 1992. Third, it has a much easier method of handling numbers and strings and than traditional Forth. There’s no need to delve into the odd data types and obscurities of original Forth. Fourth, this allows a path for Python programmers into syntonic thinking. While large, more capable projects should probably be written in a bigger, more standard system eg. gforth, Pygmy is perfect for learning Forth (and Python for that matter). There are many other benefits too, see Frank Sergeant’s excellent documentation.

Picture permission of Raspberry Pi Foundation

Here are the basic steps for installing and using the new Pygmy Forth on the Raspberry Pi. All needed files are freely available on Frank Sergeant’ssite.

  • the pi is short for Python, so any standard version of Raspbian will have a Python 3 interpreter
  • you can verify this by typing python3 –version
  • set up a directory for pygmy & your work
    (see Pygmy documentation or just use your own preferences)
  • download & unzip the pygmyforth zip file
  • execute pygmy.sh to start Python & load pygmy.fth
  • you should now be in the Pygmy Forth interpreter
  • enter and try this new word:
  • : square dup * ;
  • 5 square .
25