Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!willett!dwp From: dwp@willett.UUCP (Doug Philips) Newsgroups: comp.lang.forth Subject: New Directions: 'I' is broken in Forth Message-ID: <285.UUL1.3#5129@willett.UUCP> Date: 19 Jan 90 14:58:12 GMT Organization: Latest Link in ForthNet Chain (Pittsburgh, PA) Lines: 51 Let me say right now, that I am *not* proposing any of this for ANSI Forth. Also, the issue I want to get into here is independant of the issue I want to raise in my other 'New Directions' post (just in case you see it first). The problem, IMHO, with 'I' is that it is context sensitive, as in DO ... I ... DO ... I ... LOOP ... LOOP In this example, 'I' is not refering the same thing every place it is mentioned. State-smart words are something else in Forth that are potentially ambiguous, but at least they attempt to have the same semantics. (There are arguments for/against state-smartness, but I don't want to get sidetracked into that issue here.) How would I do 'I'? My first attempt would be to have I, J, etc. be immediate words that compile code which grabs the current index from where-ever it is that DO ... LOOP stashes it. I would not use a stack in the way that the return stack is used, in order to avoid the problem I mentioned above. In the interests of efficiency, I might even want to hack the dictionary so that, from the word being compiled, there is a known way to access the loop parameters for the loops it contains. I haven't given the actual implementation scads of concentrated thought, but there oughta be a way to do it that is both clean *and* fast. There would be, IMHO, two major gains by doing this. First, the restrictions about using R>, >R before/during/after DO LOOPS would be lifted. Second, the semantics of I J etc. would be simpler. (Isn't forth's philosophy that simpler is better :-). (The second one is what motivated this post, but the first one is just as important, now that I consider it.) I have seen reference to 'control stacks' (probably in Forth Dimensions, but I can't recall) for solving this problem. Has anyone been using them or are they just an acedemic exercise? and if 'yes', have control stacks been found to introduce new problems? (Set aside 'efficiency', for the moment, I mean semantic problems or difficulties). I'm beginning to be of the opinion that DO LOOP and its use of the return stack is not an elegant design, but rather one that was hacked on top of the existing machinery. I am also beginning to be of the opinion that Forth is flexible enough to allow you do 'do it right' and still be efficient. -Doug --- Fastest: (willett!dwp@gateway.sei.cmu.edu OR ...!sei!willett!dwp) ...!{uunet,nfsun,sei}!willett!dwp [in a pinch: dwp@vega.fac.cs.cmu.edu]