Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!ucsd!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!strath-cs!glasgow!orr From: orr@cs.glasgow.ac.uk (Fraser Orr) Newsgroups: comp.lang.forth Subject: Re: Infix operators Message-ID: <1575@crete.cs.glasgow.ac.uk> Date: 18 Aug 88 14:34:38 GMT References: <8808121826.AA23206@jade.berkeley.edu> Reply-To: orr%cs.glasgow.ac.uk@nss.ucl.ac.uk (Fraser Orr) Organization: Comp Sci, Glasgow Univ, Scotland Lines: 210 In article <8808121826.AA23206@jade.berkeley.edu> ZMLEB@SCFVM.BITNET (Lee Brotzman) writes: > > Fraser Orr wondered why we Forth programmers don't use infix operators. >Well, we could if we wanted to. I am following this message with another >that shows how to define infix operators in Forth. It takes only three >very short Forth words, plus a series of redefinitions of the words you >would like to "infixize". Well Lee, I held out a bit of hope until I read the following article. There seems to be rather a lot of spare brackets flying around in there. The purpose of infix notation is to make the program text clearer, it is not an end in itself ... "a+b+c*d" vs "a b c d * + +" vs "a +( b ) +( c *( d ) )" The last of these three is a clear looser for readability, the first is a clear winner. Anyway, that's not the point of your article, you could quite easily add infix, prefix and whatever-other-fix operators you like if you would accept a preprocessor. > Now, I guess the question is, "Why don't we want to use infix?" > > I can speak for no-one but myself when I say: I have had no trouble >learning to think in postfix. Some people do, but that is their problem. >I have had no trouble learning to keep a three-deep stack in my head. >Some people do, but that is their problem. What a very xenophobic attitude! "If people don't think the way I do then they really can't expect to understand what I'm saying!" Everyone who understands what addition means understands the "a+b" notation (yes because thats the way they've been taught), few understand the "a b +" notation (yes, because they haven't been so taught). I'm not trying to say that "a+b" is intuitvely better than "a b +" (though this is my belief - let's not argue over intuition though) all I'm saying is, if there is a well established standard (and you can't get much more well established than the infix arithmetic operators) you've got to have a VERY VERY good reason not to use it. Why has forth chosen to break this standard? Probably for the folloing reasons ... 1) It is easier to implement - as I mentioned before easy to use is MUCH more important than easy to implement. 2) You can save recalculations of intermediate results by the "drop swap flip flop" contortions - I believe that is what optimising compilers are for. 3) It gives a simple, straight forward syntax, that is easy to remember - i.e., it pretends that syntax doesn't exist, and although esy to learn, and not too hard to use, it is VERY HARD to read! These are not in my view anywhere near justification for breaking this standard, and I believe that the only reason that people aren't willing to change is because "its always been like that", and "I can read it, why can't you?", and other such nonsense. Let me also pick up on point 3 above. When Ada was being designed, they very sensible observed, that on average a program was read ten times more often than it was written, so making a program more readable, even at the expense of making it less writtable, was a wise investment (this is why Ada is such a verbose language). Now although I think they overdid it, they most certainly have a point. And all this "drop swap flip flop" (credit to whoever it was that first wrote this gem) is write only. I know, because I've got to detangle that sort of rubbish when I'm reading PostScript code. > It is simply a matter of conventions and aptitudes, that's all. Some >people get it and some people don't. It's not really a big deal. People >that like to program in Forth are not simply "unenlightened". To the >contrary, many that I have met have been the most computer literate >people I've seen. Using Forth is a matter of informed choice, not >ignorance. The majority of programmers in the world today chose to write in COBOL, any comments? > Fraser, I am sure that you have learned things that I would have a >terrible time at. My wife is comptroller of a small company, and I >can't make hide nor hair of anything she does -- it's all "magic". >Likewise, the work I do -- archival and distribution of astronomical >data -- is "magic" to her. I think it is time to accept the fact >that the problems you have with Forth are not universal. You miss my point. I don't have a problem with forth, I can program in forth. What I'm saying is that it is not appropriate in the vast majority of situations, there is a much better way. Just about all the "computer literate" people I know, recognise the value of clarity and explicitness in a computer program. Or to put it another way, they recongnise the value of syntax. I can cope with 3 deep stacks in my head, I don't want to though, the programmer should make the arithmetic and the parameter grouping explicit and unambigous in the program text. > I grant you this: Forth has a steep learning curve. It also has >rewards for traveling up that curve that are difficult, if not >impossible, to find in other languages. > > For instance, take the message that I will send following this one. >My first thought was, "Fraser Orr should see this." It was written by >Walt Pohl of Haverford College. Using three simple Forth words, he can >redefine any Forth operator as infix rather than postfix. It isn't fancy, >but it works. Can you name another language where it is so easy to change >the compiler? In C or Fortran or Pascal you are stuck with the language >constructs as they come, whether you like them or not (notwithstanding >the C macro facility). In Forth, if you don't like it, CHANGE IT! > As a matter of fact I can name some languages that do this, a language called LML provides just such a facility. Languages like C++ and Ada do so also ( though to a lesser extent). > It is this freedom that Forth programmers like. It is individualism. >I can understand that you may not like it. I only ask that you >understand that I (we) do. That is fine if programming were a solitary activity. It is not. Few if any programs are maintained, improved (or even originally written) by one and the same person, for this reason you must keep to a compromised standard that everyone agrees with. I'm sorry to be so blunt, but individualism is totally inappropriate when writting real programs. > You also mentioned in your reply to me that you applaud the innovations >to the language I listed, but you added the caveat that if they weren't >part of a standard you wouldn't use them. This I simply don't understand. >Do you mean to say that you have not built a library of functions in C for >your own use? C without it's libraries -- much of which are not standard -- >is practically useless. Extensions to Forth are like C libraries. >They are useful items that have been developed to add functionality. >Many Forth programmers have their own versions of "mylib.c", except with a >different name of course, just like C programmers. It is something we >share, not something that sets us apart. > Sorry but there is a huge difference between libraries and bolt on language features. In my C library I have routines like "Split_Line_Into_Words" and "Skip_Blank_Lines". Anyone reading these titles can make a fair guess at what they mean, and if I give a 2 line explanation, then they will know exactly and will remember exactly. But if you introduce things like structures and infix operators into a language that doesn't have them, then the poor guy comming from the outside is going to have to learn half a new language before he can hope to understand your programs. For the same reason, the extended operators in LML, C++ and Ada must be used with extreme care because if they are abused they totally obfuscate the meaning of the program. (There was a long discussion on this very subject a few months back in comp.lang.c++, if you want more on this read the archives of this group). Why am I saying, infix operators are great, but don't put them in forth because it will obfuscate the meaning? I am saying, design a totally new language on top of forth, that provides the same functionality, is parsed quickly down to forth, but has all these essential features (infix operators, syntax, structures, types and type checking, local scopes, static binding ...) as part of the standard language. > As for developing a typing system in Forth, I participated in a many- >months-long discussion about data typing on the ECFB with Mr. George >Hawkins. To summarize it now would be impossible, suffice it to >say that data typing is possible at a great expense in compile time overhead. >If you are accustomed to traditional language compilers, waiting a minute >or two to compile a program probably doesn't bother you. To a Forth >programmer, that is an interminable wait. Anything that impacts compile >time, even if it may decrease some testing time will be resisted. See my foregoing comment. > Personally, the typing scheme used in Forth, where the data are not >typed but the operators on the data are (e.g. + to add two integers and >D+ to add two double precision integers) doesn't bother me in the least. >Another one of those attitude differences, I suppose. The different names are not relly the issue here. What if you have to floats on the stack, and you apply D+? You get garbage! These sort of errors are amazingly hard to find, but they just don't occur with a decent type system. > By keeping "plugged in" to forums such as Usenet and BITNET, and the >bulletin boards like the ECFB and its "sister" boards the North Coast >Forth Board (NCFB) and the British Columbia Forth Board (BCFB), all [etc deleted] I don't have to look at builetin boards to get important features like structures, they're already provided. > > Forth isn't just a "back woods" programming language anymore, even >though it isn't as popular as Fortran, C, Pascal, COBOL, and Ada. It >has been used to control hydrogen fusion lasers, astronomical telescopes, >image processing systems, space hardware, robots, and automobiles. It >has been used to write text editors, spread sheet programs and computer >games. God knows what other applications Forth has been applied to. >I do not see these as only "very special cases" as you do. No I don't see these as special cases, just totally inappropriate things to write forth programs for. I can't think of no larger and more important program than IBM's OS/360, this was originally written in assembler, would you say this is justification for saying operating systems are best written in assembler? > > Enough of the psuedo-religious babbling. I'll stop now. Look for my >next message which contains the text of Mr. Pohl's infix operator code. > veni, vidi ..... ARGHHHHHH :^) Regards, ===Fraser Orr ( orr%cs.glasgow.ac.uk@nss.ucl.ac.uk )