Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!think!snorkelwacker!bloom-beacon!eru!luth!sunic!tut!tukki!tsaari From: tsaari@tukki.jyu.fi (Antero Taivalsaari) Newsgroups: comp.lang.forth Subject: re: interactive control structures Message-ID: <2620@tukki.jyu.fi> Date: 3 Jan 90 11:50:48 GMT Reply-To: tsaari@tukki.jyu.fi (Antero Taivalsaari) Organization: University of Jyvaskyla, Finland Lines: 72 In message <6581@tekgvs.LABS.TEK.COM> toma@tekgvs.LABS.TEK.COM (Tom Almy) writes: >One of the problems with Forth for naive users is that control structures >can only be used in colon definitions. Since users of my CAD program often >want iterative control structures but seldom need to write their own >functions, this was quite a problem. Some Forth variations (STOIC comes >first to mind) compile everything typed in and don't have this problem. I >solved the problem by having control structures force compilation if they >are executed outside of a colon definition. The result greatly enhances the >consistancy of Forth while causing no execution time penalty. We were discussing this problem with Mike Perry at FORML'89, and I agree with Tom Almy in that one of Forth's nasty features is the inhomogeneousness of the control structures. There are plenty of applications in which the interactive control structures would make things a lot easier for the user (think about a database query language in Forth, for example). In 1987 I built a Forth (for VAX/VMS) which now seems to be based on similar ideas that are used in that STOIC system you mention, although I'm completely unfamiliar with STOIC. My system, which I (at that time unaware of the other dozen systems with equivalent name) named Fifth (Fully Interactive ForTH), has many similarities to the code presented by Mitch Bradley in his reply message <8912301510.AA00667@jade.berkeley.edu>; each time a control structure word is encountered, a special counter variable is either incremented or decremented. The execution (except for the immediate words) can not take place, unless the counter variable is zero. In case of 'abort', the counter variable is set back to zero. The major difference from traditional Forth is, however, that my Fifth system never executes a word immediately (unless it is an immediate word), but it always keeps on compiling, until a special compilation ending word ('|' which I, as in Unix, call 'pipe') is encountered. Normally pressing the return key has the effect of the pipe word, too. The system has two compilation areas, one for immediate compilation and one for 'traditional' compilation. The words 'allot' and ',' are state-smart, so that the compiled code goes into either of these areas, according to the variable 'state'. When the pipe word is encountered, 'next' (return from subroutine) is compiled into the end of the immediate compilation area, and then the code in that area is executed. After execution, or in case of 'abort', the immediate compilation area pointers will be reset. The Fifth system works just fine, and it has the advantage of all the immediate words (not just control structures) being able to work equally both in the compile and execution state. Since two separate compilation areas are provided, there are no problems in error situations or in switching between execution and compilation. ...Yes, I know it isn't standard Forth anymore, but it has encouraged me to believe that there is no reason why I shouldn't be able to use DO-LOOPs and IFs interactively in normal Forth systems, too. I certainly hope that Mitch Bradley's proposals to ANSI Forth team about including interactive control structure facilities into Forth and removing the "compilation only" restriction will be seriously considered. Finally, as I am quite unaware of other approaches in making Forth more interactive, I would appreciate if someone mailed comp.lang.forth a reference list of articles in which this subject is discussed. Antero Taivalsaari University of Jyvaskyla FINLAND tsaari@jyu.fi