rob@idacom.uucp (Rob Chapman) (01/23/91)
Wil, you're inspiring. I've been disconnected from this news group for a few months now and the first thing I read when I return is Wil's BUT (no bun intended:) A comment on ALTHOUGH: right idea wrong approach. A better word would be SKIP which would skip ahead to AHEAD. Since ALTHOUGH is really just a forward manipulation of control flow, I also considered the words: FORWARD ONWARD (rlq) AHEAD FUTURE A note on SO: it seems that it might only be used for radical control flow. You defined : BUT 1 SO ; but as you mention, it is really just SWAP. This is sufficient for the simple coupling of Forth phrases with the control flow words IF ELSE ENDIF BEGIN WHILE REPEAT UNTIL AGAIN. Now, taking a departure from your factoring and F83 for control flow primitives, I present a different factoring where the marking, branching and resolving are separate words: ( ==== From botForth compiler. Syntax: { phrase }{ equivelant phrases } ==== ) { BEGIN }{ MARK } { IF }{ WHILE }{ MARK 0BRANCH } { ELSE }{ MARK BRANCH OTHER MARK >RESOLVE } { ENDIF }{ MARK >RESOLVE } { UNTIL }{ MARK 0BRANCH <RESOLVE } { AGAIN }{ MARK BRANCH <RESOLVE } { REPEAT }{ OTHER MARK BRANCH <RESOLVE MARK >RESOLVE } ( Note: this definition of FOR NEXT loops exactly n times. ) ( It does this by starting at the end, -BRANCH, which branches when ) ( the index is not zero and then decrements the index register .) ( I've sent in the next for FOR NEXT proposal, Frank. ) { FOR }{ >I MARK BRANCH MARK OTHER } { NEXT }{ MARK >RESOLVE MARK -BRANCH <RESOLVE } ( The ANSI definition would loop n 1 + times: ) { FOR }{ >I MARK } { NEXT }{ MARK -BRANCH <RESOLVE } Glossary for 8 primitives: MARK ( -- a ) note a position in the Forth. >RESOLVE ( a \ a -- ) resolve a branch forward <RESOLVE ( a \ a -- ) resolve a branch back BRANCH ( -- ) compile a branch 0BRANCH ( -- ) compile a conditional branch -BRANCH ( -- ) compile a decrement and branch >I ( -- ) compile an index setter OTHER ( a \ b -- b \ a ) swap marks to allow phrase coupling A purist might argue that >RESOLVE and <RESOLVE might be replaced with just RESOLVE and the combination OTHER RESOLVE. This would reduce the wordset by one. Either way, these words can be used to create other control structures, other than the ones defined above. It is quite simple to extend the set by adding words like ?BRANCH which could be compiled for phrases like ?DUP IF ?DUP WHILE or ?DUP UNTIL. Playing on the fringe, Rob