Path: utzoo!attcan!uunet!mcsun!cernvax!chx400!ugun2b!ugobs!bartho From: bartho@obs.unige.ch (PAUL BARTHOLDI) Newsgroups: comp.lang.forth Subject: Re: New Directions: Forth is not postfix Message-ID: <542@obs.unige.ch> Date: 7 Feb 90 10:36:44 GMT References: <284.UUL1.3#5129@willett.UUCP> Organization: University of Geneva, Switzerland Lines: 78 In article <284.UUL1.3#5129@willett.UUCP>, dwp@willett.UUCP (Doug Philips) writes: > Let me say right off that I am *not* proposing any of this for ANSI Forth. > > One of the things that is an annoying inconsistency is that > Forth is not fully postfix. The words ':', 'IF', 'DO', 'ELSE' > etc. are prefix. Has anyone out there done real postfix forth? > > For example: > > {{ I . }} 10 0 ITERATE > I came to the same idea some 15 years ago when I started using Forth, but arrived at the conclusion that what ever you do, a real language will always need some 'one word look ahead' . I think to remember that at that time they were many article around proving this (in the CS journals, not in forth). I see now three aspects of the problem : 1. From the programmer point of view, irrespectively of any compiler or code: I would be happy with : ; or 4 Four CONSTANT but not with {{ }} ITERATE neither with ' : ; The first is very natural, as in some dictionary, the second is 100% artificial, and the last not much better, but they look purer postfix ... One more word about the second construct: will we not end with the Lisp bracket nightmare, except that now we have 2 { for each ( ... 2. From the compiler point of view : The first is not very easy to recognize. You can build a temporary entry for all unrecognized words, and then fix it when you encounter ':', but all error recovery will be difficult. The second is quite easy to implement, but we recognize that the '{{' essentialy doing the same thing as 'DO' , and }} as LOOP (I am talking now at compile time, not execution time!). Further we have replaced 2 constructs ( DO, LOOP ) with 3 ( {{ }} ITERATE ). For the last, we have in fact a prefix notation which does essentialy the same as ':' when it takes the 'next' word. The only advantage is that {{ }} and ' may be used on other situations. 3. From the point of view of the generated code : The first construct could bring us to 'unbinded' entries, with 'nil' in the cfa, that could be fixed later dynamicaly. This is of course used in Lisp, but Lisp uses heavily symbolic addresses. I never explored this idea, although it seems a necessity for AI (?). I have used FORWARD DEFINE similar to pascal, and the DOER MAKE from Brodie that do this in some sens. For the second construct, we have a choice : either we compile the {{ }} and ITERATE as and where thay are in the dictionary, and we have a lot of jumps that I don't like, or we let ITERATE patch the {{ and }} in such a way for them to do what DO and LOOP would have done. I prefer the second solution, but again I am afraid of the consequence in term of security, that is what happens after an error. If you look at real life, you find that you use all notation: infix for dyadic math operator (three 'and' half ...), postfix for many quantities (12 $, or 4.75 Volt ...) and prefix for description (name: Paul ...). I don't see why a computer language should be pure in/pre/post fix. The nice things with Forth (compare to Lisp and other pre/in fix languages) is that you never need explicit brackets, you never need to read more than one word forward, you can always compile any complicated construct in 1 pass. All this is due to postfix notation + one word look ahead. If you find a 100% pure Postfix notation that add to this list without drawbacks, I will by it immediately, but I am afraid you are looking for a paradise that was lost long ago on earth! Good Forth ! Yours, Paul Bartholdi +--------------------------------------------------------------+ | Dr Paul Bartholdi bartho@cgeuge54.bitnet | | Observatoire de Geneve bartho@obs.unige.ch | | 51, chemin des Maillettes 02284682161350::bartho (psi) | | CH-1290 Sauverny 20579::ugobs::bartho | | Switzerland +41 22 755 39 83 (fax) | | +41 22 755 26 11 (tel) | | +45 419 209 obsg ch (telex) | +--------------------------------------------------------------+