Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Examples of Custom Control Flow Compiling Words

Forth famously allows users to alter the language by defining new words for control flow (beyond those given by the standard: DO, LOOP, BEGIN, UNTIL, WHILE, REPEAT, LEAVE IF, THEN, ELSE, CASE, ENDCASE, etc.)

Are there common examples of people actually creating their own new control flow words? What are some typical and useful examples? Or has the standard already defined everything that people actually need?

I'm hoping to find examples of useful language extensions that have gained acceptance or proved generally helpful to make the language more expressive.

like image 762
Raymond Hettinger Avatar asked Jun 30 '17 17:06

Raymond Hettinger


People also ask

What is a custom control?

A custom control is an area on a screen. You create them in the Screen Painter, and, like all other screen objects, they have a unique name. You use custom controls to embed controls. Controls are software components of the presentation server.

What are custom controls in C#?

Custom controls are control that are created by user when Windows Forms controls do not fulfill their application requirements. Simple custom controls can be created by inheriting the Control class, UserControl class, or any Windows Forms controls.

What is Custom Control in JavaScript?

The basic idea is that of having a control (that is a combination of different HTML tags, styles, css and event handlers) written in JavaScript that will be able to add himself to a web page or a portion of it with all his logic inside of it.


1 Answers

One another big direction of control flow structures in Forth is backtracking. It is very expressive and powerful mechanism. To be implemented, it requires return address manipulation [Gas99].

Backtracking in Forth was developed as BacFORTH extension by M.L.Gassananko in ~1988-1990. First papers on this topic was in Russian.

The technique of backtracking enables one to create abstract iterator and filter modules responsible for looking over sets of all possible values and rejecting "undue" ones [Gas96b].

For some introduction see the short description: Backtracking (by mlg), also the multi-threading in Forth? discussion in comp.lang.forth can be useful (see the messages from Gassanenko).

Just one example of 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

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

Etymology

In general, backtracking is just an algorithm for finding solutions. In Prolog this algorithm was embedded under the hood, so backtracking in Prolog is the process how it works themselves. Backtracking in BacFORTH is programming technique that is supported by a set of special control flow words.

References

  • [Gas96a] M.L. Gassanenko, Formalization of Backtracking in Forth, 1996 (mirror)
  • [Gas96b] M.L. Gassanenko, Enhancing the Capabilities of Backtracking, 1996 (mirror)
  • [Gas99] M.L. Gassanenko, The Open Interpreter Word Set, 1999
like image 70
ruvim Avatar answered Oct 19 '22 17:10

ruvim