2.  Forth and Zen

 

 

My teaching is outside Buddhist tradition,

As truth cannot be conveyed by writings;

Cleanse your mind to reveal your true nature;

One can reach Nirvana directly.

 

Buddhidharma (~550AD)

 

 

Forth is often mentioned not only as a computer language but also a religion, because of its feverish followers.  Among the many real religions, Zen is considered to be the closest to Forth.  As popularly known, Zen is understood as a synonym of simplicity, brevity, light, understanding, wisdom and enlightenment.  These are also attributes to Forth as a language and a philosophy.  Indeed, Zen and Forth also bear striking similarity in their historical development and evolution.  Here I like to explore the similarity between Forth and Zen, and perhaps learn something which will help us writing better code.

 

Zen and Forth both started as revolutions against well entrenched establishments--the priesthood.

 

Zen and Forth both started as oral traditions because of the lack in supporting literature and the high concentration of expertise, which is not easily dispensable.

 

Zen and Forth both stressed that their matters of subject were simple and straightforward.  However, it was in the interests of the entrenched establishment to make things complicated and inaccessible to common folks.

 

Zen and Forth both stressed that the true enlightenment and understanding were within the grasp of individuals.  The rituals and the accepted practices exercised in the establishments had nothing to do with these goals.

 

Here I would like to compare Zen and Forth in greater details so that we all have a better appreciation of these two seemingly unrelated topics.  Forth programmers may be encouraged to press on using this language with a higher hope that their work will be recognized by their peers in the future.

 

 

2.1           Histories of Zen and Forth

 

Historically, Zen was a grand synthesis, combining the essence of Buddhism, Confucianism, and Taoism after about one thousand years of cross fertilization.  It was the results of the many Chinese minds, struggling for emancipation after a thousand years of conflicts between the traditional humanistic Confucianism, the nihilistic Taoism and the imported anti-materialistic Buddhism.  It laid dormant for a a couple of hundred years, surviving through five generations of Zen masters, passing the doctrine orally from heart to heart.  Eventually, during the reign of the Sixth Patriarch, Huineng (638-714 AD), it blossomed in full and became the dominating religious philosophy in China ever since.  Its influence spread into Japan, Korea, and Southeast Asia.  Lately, it also became fashionable in Western Europe and America.

 

The history of Forth is too short for meaningful comparison with that of Zen.  It was virtually unknown to the world in its first decade of existence.  Then it blossomed with the microcomputer revolution, promoted by the Forth Interest Group in the early 1980's.  Since 1985, the Forth Interest Group has been in steady decline, as C became the dominant programming language.  Is Forth in the dormant period now?  Will it blossom again someday and become the dominating programming language?  Nobody knows.  I certainly hope so.  The many ideas and technology embodied in Forth seem to be so pristine, powerful and all-encompassing, it is hard to imagine that this precious jewel could be ignored for long.

 

 

2.2           The Oral Tradition of Zen

 

Buddhism was founded by Gautama Siddhartha, a religious philosopher and teacher who lived in India (~560-480 B.C. ) He was called Buddha which means the enlightened one.  He attracted a large following.  His teaching in essence was that one could reach Nirvana, a divine state of release from earthly pain, sorrow, and desire, by the right living, the right thinking and self denial.  He left no writing behind, while Buddhism flourished in India for a long time.

 

In the two hundred years after Buddha's death, many schools formed after different personalities and there were great arguments and debates concerning what was his true teaching.  Great conventions were held to debate the issues and codified his teachings as Sutras in Sanskrit.

 

The earlier dominant school was Hinayana, which spread to the south and is still flourishing in Sri Lanka, Burma, and Thailand.  The later dominant school was Mahayana, which spread into China, Tibet, Korea, and Japan.  The Hinayana School emphasize the mystic power of Buddha and the personal salvation through one's own efforts.  The Mahayana School emphasized eclecticism and in collective search for salvation.

 

After the introduction of Mahayana into China in 200 AD, it arose great interests among the intellectuals as well as the peasants.  Many emperors and their courts were converted and they spent great efforts in building temples and spreading the Buddhism.  A continuing effort over three hundred years was devoted to translate Sanskrit Sutra and related literature into Chinese.  In Tang Dynasty (618-907 AD), more than 5000 volumes of Buddhist literature were translated and assembled.  Most of the Sutra translations were done poorly and required a priesthood for the interpretation and dissimulation.  The vast amount of literature also caused sectarian divisions and arguments among the priesthood, continuing the Hindu tradition.

 

Zen was introduced into China by a legendary Indian monk Buddhidharma in 527 AD.  He stayed at the Shaolin Temple for 9 years, spending all his time meditating in front of a stone wall.  He was known as the 'Indian Monk Looking at a Wall'.  He didn't use any Sutra, and he didn't write anything.  He taught a few students and encouraged them to find enlightenment in themselves.  His teaching was summarized as:

 

My teaching is outside Buddhist tradition,

As truth cannot be conveyed by writings;

Cleanse your mind to reveal your true nature;

One can reach Nirvana directly.

 

Buddhidharma passed his garment and his begging bowl to his student Huiko as evidence of the discipleship and commanded him to do the same for five generations.  He then returned to India.  Huiko passed the teaching with the garment and the bowl to Sengtsan.  Sengtsan passed them to Taohsin.  Taohsin passed them to Hungjen.  Finally, Hungjen passed them to Huineng (~660 AD).

 

For a couple of hundred years, Zen was passed from mouth to mouth, and from heart to heart.  Very few people knew of its existence.  Even fewer knew its philosophy and teachings.  In China, Buddhism flourished when supported by the emperors and by high officers.  A number of times the Buddhism was almost completely destroyed when the country was in turmoil and when the Confucian officers could convince the emperor that Buddhists were threats to the state.  All the while, the Zen masters orally passed their teachings from one generation to the next.

 

 

2.3           The Orally Tradition of Forth

 

Forth was invented by Charles (Chuck) H. Moore in the sixties.   He was trained as a physicist in MIT but wandered into programming.

 

In early days, he built an interpreter so that it would execute words on punched cards.  Later he found that these words could be more conveniently compiled into lists, which could be executed by the computer more conveniently.  The interpreter with very little modifications, could be made to compile anything and everything, and the whole scheme evolved into a programming language.  It was named Forth, as abbreviated from Fourth, meaning the fourth generation of programming language, when the third generation of computers bases on integrated circuits were becoming prevailing in the computing industry.

 

Very early in the development of Forth, a state of closure was reached.  Chuck was able to generate new Forth systems from an existing Forth system through meta-compilation.  He did not need other programming tools to build new Forth systems, and Forth started to evolve independent of the existing operating systems and programming languages.  This state of closure was very interesting, like the ying-yang cycle.  One could not find an entry point once the cycle was closed.  In that Chuck had the monopoly on Forth, because very few people possessed the understanding to cut in the cycle in order to build new Forth systems.  He felt quite secure in giving users the complete source listings, fairly sure of that nobody could reversed engineered the Forth technology, even though the source listings were complete and truthful.

 

Indeed, the source code was very difficult to read, because a Forth system was generated by the meta-compiler, and the meta-compiler was written in Forth.  To understand Forth, one had to understand the meta-compiler.  To understand the meta-compiler, one had to understand Forth completely.  Where do you start?

 

Forth thus became a legend.  The astronomers loved it so much that the International Astronomy Society made it the standard language for observatory automation in 1974.  It was fairly easy to use but very difficult to understand.  The source code traveled to the far corners of the world with the telescopes, but the knowledge and understanding of Forth was only passed from mouth to mouth and heart to heart.  Hence Forth became an oral tradition these days.  Forth code tended to be concise and often packed tightly in blocks.  In-line documentation and comments were deemed too expensive, and most code was not documented at all.  Forth thus acquired the reputation of a write-only language.

 

Several manuals were circulated among the observatories, documenting a few of the most popular Forth implementations(1).  These manuals mostly contained a short section intoducing Forth and discussing how to use that particular Forth system, and a long dictionary documenting what each word did.  These manuals told the users what Forth was, but provided very little help as to how Forth worked.

 

 

2.4           The Breakthrough of Zen

 

Huineng, the Sixth Patriarch, was a genius.  He couldn't read because he was borne poor and gathered wood for a living, but he could explain the Sutras when people read them to him.  He went to learn from the Fifth Patriarch Hungjen, and Hungjen sent him to labor in the kitchen.  As Hungjen got old and wanted to pass on the garment and the bowl, he asked his students to write poems to show him their understanding of the enlightenment.  His best student Shenhsiu wrote the following poem:

 

My body is the bodhi tree,

And my mind a mirror bright.

Carefully I wipe it hour by hour,

And let no dust alight.

 

Hearing this poem, Huineng asked a scholar to write down his own poem, because he couldn't write himself:

 

There is no bodhi tree,

Nor stand of a mirror bright.

Since all is void,

Where can the dust alight?

 

When Hungjen saw this poem, he passed the garment and the bowl to Huineng and told Huineng: "You are the one Buddhidharma prophesied.  Zen will flourish in China through you.  Take the garment and the bowl to be the Sixth Patriarch, but do not pass them on any more.'" Hungjen was in such a hurry to pass things to Huineng that he didn't even shave Huineng's hair (to admit him to Buddhist order), as Huineng was still a layman.

 

About 20 years later, when Huineng was well established as the Master of Zen, he was asked by a Provincial Officer to give lectures on Zen.  The Officer had Huineng's eldest student Fahai recorded his lectures and had the lectures printed as the 'Platform Sutra, Lectures by the Six Patriarch'(2).  When Huineng was about to die, Fahai asked him: "What are you going to do with the garment and the bowl?  Who's going to inherit them?"  Huineng said: "As commanded by Buddhidharma, the garment and the bowl will not be passed on.  But now you all have the Platform Sutra.  Go forth and teach others according to this Sutra.  Everything I learned I put down in it.  When you read it, it is as if you are listening to me."

 

20 years after Huineng died, the Northern School was still favored by the royal court and dominated the Buddhist landscape in the cemtral China.  The Southern School was scattered and mute in Southern China.  One of Huineng's student, Shenhui (686-760 AD), went to the capital and challenged the doctrine and the Zen heritance of the Northern School in a series of lectures and public debates.  He convinced the court and the public of the historical significance of Huineng and established the Platform Sutra as the orthodox doctrine of Zen Buddhism.

 

 

2.5           The Breakthrough of Forth

 

The major breakthrough in the Forth arena was due to the Forth Interest Group, which was founded by Bill Ragsdale in 1978 in the Silicon Valley.  The most important contribution FIG made was to reverse-engineer a Forth system from ground zero, thus breaking the infinite ying-yang cycle.  FIG organized a Forth Implementation Team which built and released 6 Forth implementations for the 6 then most popular microprocessors based on the figForth model(3).  These implementations were written in assembly code of the native microprocessors.  People who were familiar with the assembly code could then easily implement figForth on their own microcomputers.  figForth thus trained a new generation of Forth programmers outside the Forth oral tradition.

 

There was a host of Forth literature appearing in the early 1980's, which further helped the popularization of Forth among the personal computer users.  Among them were Leo Brodie's 'Starting Forth' (4), 'Thinking Forth'(5), and the 1980 Special Forth Language Issue in the Byte magazine.  'Forth Dimensions' from FIG and 'Journal of Forth Applications and Research' from the Forth Institute were the two major publications on Forth.  These literature showed that Forth penetrated into many different scientific communities and technical industries.

 

My most important contribution to Forth was the publication of 'Systems Guide to figForth' (6), first released in 1979.  Instead of telling people what Forth did, it systematically explored how Forth did things and why things were done the ways they were.  It put to rest the myth that Forth was a write-only language by showing that Forth could be understood by averaged user with somewhat casual studying.  It showed how the inner interpreter and the outer interpreter worked, and why words and dictionary in Forth were constructed the ways they were by necessity.  It proved that the understanding of Forth could be transmitted through the paper medium without personal interaction.  The impact of this work, I would like to believe myself, was similar to what Huineng caused with his Platform Sutra on Zen.

 

 

2.6           Simplicity in Zen

 

Buddhism is very complicated because it is not a monolithic system of thoughts and philosophy.  It accumulated many centuries of religious, cultural and philosophical development.  The Sutras were all attributed to Buddha but were most likely written by people very remotely associated with Buddha.  Lots of the mystic Hinduism found their ways into Buddhism, which was inevitable because Buddhism was developed in the Hindu environment, like the 33 layers of heaven, 18 layer in hell, the reincarnation of all animals, etc.

 

There were many different theories about life, death, and Nirvana.  There were many sectors and schools about how one could attain Nirvana to avoid the reincarnation into a lower animal form.  Thing got complicated and confusion reigned supreme.  In essense, everybody just picked what he believed and convinced others that his was the best and most logical way to deal with life and all its ramifications.

 

The general consensus was that vegetarianism was good, giving to the temple was good, kindness to people and animal was good, reciting Sutra was good, mediatation was good, worshiping Buddha and other buddhist deities was good, dedicating to priesthood was good, etc.  Could one attain Nirvana by doing all these?  Maybe.  Maybe not.

 

Zen was a great simplification of all these.  Huineng maintained that Buddhahood and enlightenment could not be achieved through generally accepted Buddhist practices, like reciting Sutras, making offerings, mediatation in special sitting positions.  As everybody alread had the Buddha nature in him, all he had to do is looking inward to find the true Buddha.  Our senses and our thoughts tended to veil us from the Buddha nature and they should not be trusted.  The process of Zen (Dhyana, Ch'an, meditation), was to reject the influences of senses and thoughts, and to arrive at a state of ideallessness, nonobjectivity, and nonattachment.  In this state, nothing external of ourselves and within our own minds can influence us and dragged us back to the earthy existence.

 

Since Zen could be practised by layman as well as monks and nuns, it was welcome by all segments in the Chinese society, especially the Confucian intellectuals and the common peasants.

 

 

2.7           Simplicity in Forth

 

The poem by Shenhsiu and the poem by Huineng provide the best contrast for us to compare the conventional wisdom in the current computer industry against the Forth philosophy.  Let me paraphrase the poems to show my point.

 

From the mainstream of the computer science, one would advice our youngster:

 

Hardware is complicated,

Software even more so.

Study hard day and night,

You may find something useful to do.

 

From the point of view of Forth, we might say:

 

Hardware is ever changing,

Software but an illusion.

Learn your Forth well,

You can beat both to submission.

 

Computer hardware is difficult.  Computer software is even more difficult.  We have volumes and volumes of literature to prove them.  Hardware and software are difficult, only because people are not given the right tools to deal with the complexity in these systems.  If we insist on asking whether the complexity is necessary, we can convince ourselves  that they should not be complicated.  The computer hardware evolved trying to solved the perceived software problems.  The software evolved trying to solve the perceived hardware problems and the problems in the human interface.  If these preconceived problems do not exist at all, the hardware can be simple and powerful.  The software can be even simpler and more powerful as well.

 

Chuck Moore went through the very long process of eliminating what was unnecessary and superfluous in the software, by creating a Virtual Forth Engine with an extensible instruction set.  New instructions (words) can be added freely to replace lists of existing instructions.  Building new instructions brings the system to higher levels of abstraction, towards an efficient solution to any application problem.  Lists can be nested indefinitely on a return stack.  Parameters as input to an instruction and outputs from an instruction can be nested indefinitely on a data stack.  This dual-stack architecture allows lists to be interpreted and compiled very conveniently, and resulted in a simple, yet extremely powerful, operating system and a high level programming language.

 

Forth is much more than an operating system and a programming language.  It is a very efficient design of a hardware CPU core.  The dual-stack architecture is best implemented in hardware.  Now that we can integrate million of gates on a single chip, it is possible to put Forth CPU core on the chip, together with the entire operating system, the programming language, and the intended application.  System-On-a-Chip (SOC) will be the best vehicle to carry Forth into the 21th Century.

 

 

2.8           The Enlightenment in Zen

 

Zen was the cumulative synthesis of the Buddhist philosophy and the traditional Chinese Confucianism and Taoism.  Zen was also a revolution against the Buddhist traditions and establishments.  It discredited the Buddhist practices, which emphasized ceremonies and outer appearances, while claimed that the enlightenment exists only in the minds of individuals.

 

A huge amount of Buddhist literature had been translated from Sanskrit to Chinese.  Because the translations were difficult to understand, a priesthood was established for its dissimulation and interpretation.  Towards this literal tradition, the Zen masters proclaimed that enlightenment could not be transmitted by written words, but had to be handed done orally from heart to heart.

 

In the traditional Buddhist theories, it was very difficult to attain Nirvana or Buddhahood.  It required a long time of studying, and the practice of self-denial.  In the end, there was still no assurance that one could attain it.  Even if one attained it in this life, there would be the possibility of losing it in the next life.  There were external forces which we could not know and we could not avoid.

 

Zen placed the possibility and the capability to attain enlightenment and Buddhahood squarely in the individual.  It declares that the Buddha nature is part of the human nature and it exists in everybody.  The Buddha nature is veiled and corrupted by the worldly desires and thoughts.  These desires and thoughts can be purged, the individual can thus be enlightened, and his own Buddha nature can reveal itself.  The enlightenment is the realization of this self-sufficient Buddha nature.

 

As to how one became enlightened, there were two major schools of thoughts.  Huineng insisted that enlightenment came suddenly and Senghsui maintained that it ought to be the results of diligent study, mediation and searching.  These were the Southern Sudden School and the Northern Gradual School.  However, as Huineng maintained, how enlightenment is achieved is not important.  The important thing is its realization.  People are all different, and they are enlightened in different ways.  A master can teach, but he can not enlighten.  The enlightenment comes from within.  The best a master can do is to inspire, to help, to lead the way, and maybe to strike a sharp blow on the head of a student at the right time.

 

 

2.9           The Enlightenment in Forth

 

What is the enlightenment in Forth?  I think it is the complete understanding of a computer in terms of its operations and its interface to the user.  This understanding is not as complicated as we have all being led to believe.  It involves two components of Forth: the inner interpreter which Forth imposes on the computer hardware to execute Forth lists, and the outer interpreter which executes words typed in by the user.  If one understands both the inner interpreter and the outer interpreter, he has the complete understanding of computer, in the sense that he can go out and build a Forth system on any computer and make that computer do what he wants it to do.  He then will realize that operating systems and languages enslave people to do what the system permits them to do, while Forth gives them freedom to tell the computer to do what they want to do.  This is enlightenment.

 

Operating systems and programming languages are designed to enslave the users, by their sheer sizes and their complexities.  They are too complicated to be understood by individual users.  Forth shows that an operating system and a high level programming language do not have to be complicated.  In fact, they can be very simple and can be mastered by individuals with some limited efforts.  Once the principles are mastered, they can be applied to all computers.  Then, the user can become the master, and the computers become obedient but powerful slaves.  To be the master of powerful slaves is very enlightening and satisfying.  Once you taste the freedom and the satisfaction of being the master, you will not want to be enslaved again by a computer through its operating systems and programming languages.

 

From my own experience and from the experiences of many friends, the best way to achieve enlightenment in Forth is to build your own Forth system.  You have an application problem you want to solve.  You have a board with a micrprocessor, some memory, and some IO devices on it.  The fastest way to bring you application to live is to implement a Forth for the microprocess and bring the Forth up.  After the Forth is running, the application will almost solve itself.  If there were anything you did not understand in Forth or in you microprocessor, you could not bring the Forth system up.  However, after many sleepless nights, you will find the problems in your implementation and get the Forth system to behave correctly.  When this happens, you will attain enlightenment.

 

I designed the eForth system to help you go over the hump.

 

 

2.10         eForth Sutra

 

The most important contributions of Huineng to Zen was that he had his lectures recorded by his disciples.  He also had the lectures printed and distributed as identifications of discipleship to his teaching and his philosophy.  In striking contrast to the Buddhist Sutras translated from Sanskrit, the lectures were plain, easy to read and to comprehend.  This collection of lectures was the only book written by a Chinese to be granted the status of a Sutra in the Buddhist literature, and is commonly call the Platform Sutra.  In the Chinese literature, Sutras were the teachings and writing of Confusous, Laotze, Buddha, and the most influencial persons in major schools of thoughts.

 

With a greatly mixed feeling of pride and humility, I named this bood ‘eForth Sutra’.  The word Sutra is not used casually.  The subject matter is very serious and important to the computer industry and to the programming public.  By systenatically presenting Forth as an operating system, a porgramming language, a hardware CPU design, and all the tools which are necessary to make this CPU to work properly, I hope to convince you that this is the right technology that you can used to solve your own problems.  Once you mater these tools, you will be able to seek freely the best path to design your own computer and to find the best solutions to your computer related problems.

 

 

 

References

 

1   M. S. Ewing, The Caltech Forth Manual,  2nd Ed., 1978.

2.  The Diamond Sutra & The Sutra of Hui-neng, translated by A. F. Price and Mou-lam Wong, Shambhala, Boston, 1990.

3.  William F. Ragsdale, figForth Installation Manual, Forth Interest Group, 1980.

4.  Leo Brodie, Starting Forth, Prentice-Hall, 1st Ed., 1984; 2nd Ed. 1986

5.  Leo Brodie, Thinking Forth, Prentice-Hall, 1984.

6.  C. H. Ting, Systems Guide to figForth, Offete Enterprises, 1981.

7.  C. H. Ting, Forth and Zen, Offete Enterprises, 1993.