Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!decwrl!ucbvax!ucsd!sdcc6!ir230 From: ir230@sdcc6.ucsd.EDU (john wavrik) Newsgroups: comp.lang.forth Subject: Learning Forth Message-ID: <4600@sdcc6.ucsd.EDU> Date: 3 Aug 89 05:48:28 GMT Organization: University of California, San Diego Lines: 75 SCFVM.BITNET!ZMLEB (Lee Brotzman) writes: > I don't think that Forth is easy to learn. But, I think that time spent > learning Forth is time well spent... I have used the techniques I gained > from an intimate knowledge of Forth in other, "academically accepted", > languages. > This may be a harsh statement, but I still think that the only way that > Forth can be truly appreciated is to write a Forth interpreter on you own. > At its heart, Forth is extremely simple. In its soul, Forth is something > that approaches enlightenment. With a small amount of knowledge about how > computers work, and some assembly language programming, Forth is yours. > Just remember that Forth is not hard, it is only different. ------------------------------------------------------------------------- LEARNING FORTH FORTRAN, BASIC, Pascal, C, ADA, etc. belong to a family of similar languages. Learning one after having learned one of the others is a relatively minor matter of coping with a new syntax. Compound statements may be delimited by BEGIN .. END in one and curly brackets in another; statements may be terminated or separated; the terminator/separator may be a semi-colon in one language and a comma in another; keywords may vary: "case" may be called "switch"; "print" may be called "write"; etc. One of my students, a faculty member steeped in the lore of these languages, expressed his frustration at being unable to translate his pre-conceived ideas to Forth by saying "What kind of crazy language has 800 keywords?". Any learning depends on "organizing principles": techniques or devices used to make sense of a body of information. Forth can appear hard to those who have learned other languages because they have the wrong organizing principles. They have been trained to avoid involving themselves with how the how a language is implemented. Compilers for conventional languages are very complex, and conventional wisdom is that the user should not have to know anything about them. ("How a compiler works is no more of interest to a programmer than the details of an internal combustion engine is to the driver of a car." --anon) Forth requires a different set of organizing principles. It is learned most easily by understanding how it works. Indeed, Forth's main claim to fame is that it trades built-in features for users' knowledge. Forth is an assembly language for a virtual machine which can be implemented on any real computer. The virtual machine has two stacks, two stack pointers, and an instruction pointer. Code is compiled as a sequence of addresses of component words. Etc. Words can be understood in terms of their actions (typically in terms of what they do to the stack). A mental image of the underlying virtual machine provides a powerful organizing principle. It is not necessary to write a Forth system to learn Forth -- but one should learn on a system for which the source code is accessible on-line. Forth is more a toolkit for building languages than a language itself. By providing a low level base, Forth allows the user to make extensions and modifications which, for conventional languages, would require the services of a professional compiler writer. By providing a mechanism for extensibility, Forth permits the user to build a tailor-made high level language. Unlike most assembly languages, the commands of Forth can be used interactively. This has been found to speed development (and makes it easy to produce an interactive application language). Since Forth includes the elements of an operating system, highly portable complete systems can be created which include I/O from keyboard, console, and mass storage. Forth, as conceived of by Charles Moore, has both power and portability. A user's access to the implementation is only half of the virtue of Forth. The other half is that the implementation is simple enough for the access to be useful. The simplicity of Forth's implementation is the key both to understanding the language and to its power. --J. Wavrik