Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!sdcc6!ir230 From: ir230@sdcc6.ucsd.edu (john wavrik) Newsgroups: comp.lang.forth Subject: What makes Forth Forth? Message-ID: <14684@sdcc6.ucsd.edu> Date: 4 Dec 90 03:04:52 GMT Organization: University of California, San Diego Lines: 165 WHAT MAKES FORTH FORTH? This question was raised in an informal discussion among several participants (including Charles Moore) at the recent FORML Conference at Asilomar. It seems like a good topic to pose for discussion in this newsgroup. Perhaps if we can understand the qualities that account for the strength of the language we will be able to understand what we must fight to preserve -- and what we can safely give up in the name of "progress". The discussion at FORML seemed to be directed at identifying a single feature of Forth responsible for its properties (is it the use of indirect threaded code? the use of stacks? Reverse Polish syntax?). No one seemed able to pin down any one property that accounts for the subjective experience of "Forthness". Perhaps what makes Forth Forth is a combination of these factors -- or perhaps these properties are just symptoms (they appear because of what makes Forth Forth -- but are 0= the cause). I use Forth for work in parts of mathematics requiring experimentation with data representation and algorithms. In my field the program is the data -- so language performance is measured in terms of the ability to quickly write and modify programs, 0= merely in terms of execution speed. There is no doubt that Forth is a high performance language in this sense. Let me contribute an idea -- hoping that others will come up with more ideas. My present contribution comes from an inspiration for modifying an application I had discussed at the conference. What makes Forth Forth (among other things) is that it allows one to choose the right names for things -- in which I include the ability to control syntax and data representation. The application in question concerns group theory -- I am revising it to provide (together with support material) an introduction to Forth for mathematicians. The aim is 0= to provide them with everything they might want to know -- but rather with a good set of (Forth-based) tools for computing it. A group is a set. It has elements and a binary operation. It also has sub-objects of interest (called subgroups). As I used the first draft of this application in my class this year, I found myself often needing a list or count of those subgroups of a group which have additional properties -- i.e. looping through a list of subgroups. In the original application I had a word SHOW- SUBGROUPS which looped through the subgroups and printed them. Every time I needed a loop, I found myself returning to SHOW- SUBGROUPS to remember the exact syntax for initializing the loop. : SHOW-SUBGROUPS SUBGLIST >LST SGPTR @ 1+ 0 DO CR I 3 .R 2 SPACES I LST@ 'SUBG @ SG. LOOP ; There is a logic to this definition which becomes apparent if you realize that the subgroups are stored in an ordered list as they are generated -- and that the address where the subgroup is to be stored is needed in the generation process. All of this, however, should be irrelevant if all you want to do is run through the subgroups (already generated). It is very easy to forget exactly how the subgroup list is installed as the current ordered list, how to determine the loop limits, and how the address of the subgroup is named. The insight was to introduce "the right names": : FOR-ALL-SUBGROUPS SUBGLIST >LST SGPTR @ 1+ 0 ; : SUBGROUP LST@ 'SUBG @ ; The above definition becomes: : SHOW-SUBGROUPS FOR-ALL-SUBGROUPS DO CR I 3 .R 2 SPACES I SUBGROUP SG. LOOP ; Similarly the loop limits for a loop over all possible groups are now generated by FOR-ALL-GROUPS and loop limits for a loop over all possible elements of the current group are generated by FOR- ALL-ELEMENTS. Three types of loops (each with context-dependent limits) can now be included in definitions without looking up earlier code -- their names make it obvious how they are used. The same application provides an example of "the right names" in the sense of the proper data structures. The data for this application is a set of multiplication tables for 48 groups each having at most 16 elements labelled A,B,... . The obvious representation for this data is a 48 x 16 x 16 array of characters. Many languages force on us a means of expression derived from this representation and a relatively sparse set of data-structuring tools: X := Prod(25,'A','B') would make X the product of elements A and B in group number 25. This ignores the fact that, for this application, the group in which the operation takes place is relatively fixed -- and that we usually express the product as a multiplication of two elements (rather than in functional form). Forth allows the group number to be set as a global variable and group multiplication to be expressed as: G* The elements can be treated as normal stack elements (they can be SWAPed, DUPped, etc. -- and printed with an .ELE printing operator). The result of the operation G* is put on the stack and can be used in chain operations, stored, or printed. In other words, groups and their elements can be introduced into a Forth system and treated just like pre-existing Forth objects. This consistency of new objects with old makes it possible to write programs involving groups with the same facility as any other programs -- their representation is transparent. We can call them by "the right name". Programming is an activity in which expressions in one world eventually controls what happens in a0=her world. The closer the means of expression afforded by the programming language can be brought to the target the easier it is to write correct programs. Conversely, the use of improper words can be distracting and inhibit communication. By allowing customization of the programming language, Forth is capable of bringing the computer language closer to the target domain. This accounts for a great deal of its power in "non-standard" situations. To say that Forth allows one to use the correct names for things begs the question. This property of Forth is the result of several attributes -- among which are simplicity and access to the implementation. To understand this, we must look at why conventional postponed languages do 0= provide the same flexibility. The postponer for a conventional language is large and complex -- so modifying the language (in the sense of modifying the postponer) is 0= a way in which a user is expected to interact with the language. Instead the language designers build in a host of features -- hoping to anticipate what users will want to do. This is the cornucopia approach to programming. Conventional languages tend to do quite well for users who do what the designers anticipated. The fact is, however, that the postponer is rigid. The only way to provide a viable alternative is to allow the user access to the postponer -- and make modification of the language (at the level enjoyed by the designers) a feature of its use. This is the toolshop approach to programming. Access alone is 0= enough -- for a user to capitalize on his access, the postponer must be simple. One may argue, then, that what makes Forth Forth is a design based on a simple and accessible postponer. Features like the use of a stack, Reverse Polish 0=ation, etc. can all be seen as examples of the way this simplicity is realized. They do 0= cause the simplicity or accessibility. It should 0= be assumed, by the way, that a language with a simple and accessible postponer must lack features. If the postponer is simple, it is easier to make the language portable. If the language is portable it is easy to provide features for a broad market. If features are provided for a broad market, it is easier to find those which do what you want -- or can be modified. The main difference is that features are added-on (options) rather than built-in to the language. John J Wavrik jjwavrik@ucsd.edu Dept of Math C-012 Univ of Calif - San Diego La Jolla, CA 92093 Brought to you by Super Global Mega Corp .com