User Control Flow Examples Word Compilation

Forth famously allows users to change the language by defining new words for the control flow (in addition to the values ​​specified by the standard: DO, LOOP, BEGIN, UNTIL, WHILE, REPEAT, LEAVE IF, THEN, ELSE, CASE, ENDCASE, etc. ..)

Are there common examples of how people create their own new control flow? What are typical and useful examples? Or has the standard already defined everything that people really need?

I hope to find examples of useful language extensions that have been recognized or have been found to be generally useful in order to make the language more expressive.

+8
compilation control-flow forth gforth
source share
2 answers

Another important area of ​​Forth flow management structures is backtracking . This is a very expressive and powerful mechanism. Implementation requires return address processing.

Rollback in Fort was developed as an extension of BacFORTH M.L. Gassananko in 1988-1990.

The first reports on this topic were in Russian. For some introduction, see a brief description and the article Strengthening the possibilities of backtracking by M.L. Gasananko (1998). See Also discussion in comp.lang.forth (messages from Gassanenko).

Just one example generator in BacFORTH:

: (0-2)=> PRO 3 0 DO I CONT LOOP ; \ generator : test (0-2)=> CR . ." : " (0-2)=> . ; test CR 

Output:

 0 : 0 1 2 1 : 0 1 2 2 : 0 1 2 

PRO and CONT are special control flow words. PRO stands for generator word, and CONT calls the user - it's something like yield in Ruby or ECMAScript. A number of other special words are also defined in BacFORTH. You can play with BacFORTH in SP-Forth (just include the ~profit/lib/bac4th.f ).

Morphological

In general, backtracking is just an algorithm for finding solutions. In Prolog, this algorithm was built into the hood, so backtracking in Prolog is the process of how it works. Rollback in BacFORTH is a programming method supported by a set of special control flow words.

+7
source share

Here is one example. CASE was a somewhat late addition to the Forth flow control word set. In early 1980, a contest was announced at Forth Dimensions to determine the best CASE status. It was resolved later this year with a tie between the three entries. One of them was in the Forth94 standard.

+6
source share

All Articles