How to read VPGL diagrams – vpgl.net

This page guides you how to read VPGL diagrams to understand other examples in this site and to make your programs.

VPGL diagrams are sized in 3×3, 5×5 or 7×7 grid. each grid element “tile” is empty or has a method name, input arrow(s), an option if needed, and output arrow(s) if needed.

VPGL has OBJECT-ORIENTED features in its execution:

Diagrams consist of square tiles have a operation name. This name is method identifier for target object. Target object is the object comes from specified direction or first arrived object. The target object searches the definition about what to do associated with method name of this tile. then execute found definition. This execution emits 0 to 3 outputs. Then dispatching them to next tiles may makes to be able to get ready to execute.

VPGL executor picks tiles ready to execute and executes them until no tiles is eligible to execute.

Anyway, now take a look at the first example.

In below example, the tile D1 has “CONST” as method name, “HELLO WORLD” as its option, input 0 from top, then output 0 to bottom. You can see the full description about D1 by tapping on the center of D1 tile.

See below first.

This is the first example which only displays “HELLO WORLD” message. The VPGL executor will start running by drop an object of App class to top side of D1 tile.

This App class object falls into D1 tile from top edge as Input 0 as labeled “I0” (“Input #0”). Input 0 object (App class object) picks the method name of this tile and option, then finds the definition of how to do for this method “CONST” in its object it self. (If input 0 object does not have no definition about picked method name, an error about “unknown method” will be reported and abort the program.)

App class object “knows” how to do about CONST as a system defined method. This makes a new object described in option (A string object represents “HELLO WORLD” in this case), then emits this new object to output 0 (labeled “O0” – output #0). The reference of entered object is discarded. So the result of processing D1, A string object “HELLO WORLD” goes to top edge of D2.

Next, this string object “HELLO WORLD” to head side of tile D2. Tile D2 having method ALRT .

String object knows how doing with ALRT, String object do ALRT as popping up an alert dialog having a message represents itself, then it goes out through output 0.

Tile D3 has 1-input/0-output and displayed italic “STOP“. STOP terminates the execution of this program immediately when the input token arrives even if there are other flowing object tokens in this program space.


Next example has more tiles to step ahead.

This example diagram calculates summation of number N that is:

Sum(N) =1+2+3+…+N=(N*(N+1))/2

This diagram implements (N*(N+1))/2 which is no need looping.

you can see VPGL execution by pressing RUN on above example.

As same as the first example, VPGL executor drops an App class object on the head side of tile D1 to get starting.

D1 tile commands INPUT to arrived token with option “INPUT a positive integer”. App class object knows INPUT as operation opening a INPUT dialog with option value as prompt, taking input from user, then putting object taken by dialog to its output 0. Note that arrived token is discarded. So after end of D1, a Number class object gets out by valid user input operation.

Tile D2 accepts user input token from D1. D2 has one input and three outputs without method and option. No method displaying tile is the simplified notation of FLOW method tile. FLOW is known by all objects, and commonly doing same action. If tile has 1 input and 3 outs, the reference of arrived token will be made 3 copies and put to output 0, output 1 and output 2 for each. (Note that “copy” means duplicating its reference, not object it self) after executing tile D2, copied tokens are distributed to tile C2, D3 and E2 one token for each.

You can see red numbers near for each arrow. Each input/output arrow have a number started from 0. D2 tile has input 0 as from top, output 0 to bottom, output 1 to right and output 2 to left. (Double tap/click on D2 tile, grid will be magnified. )

E2 tile is CONST method tile as mentioned above with option as number 2. E2 put number 2 to output 0 directed to bottom.

Tile C2 is “n+1” method commanding. Number object knows it as add 1 to itself then put result to output 0 directed to bottom.

Tile C3, E3 and E4 have input 0 and output 0 without method displayed. This FLOW tile which has 1-input/1-output is known by all objects as passing itself to the output 0.

After executing these FLOW tiles, tile D3 can get start because both input 0 and input 1 are arrived from top and left each.

D3 is “A*B” method tile which is known as making a Number object represents product of input 0 and 1 and put it to output 0 by Number object. In this diagram, D3 put n*(n+1) to output 0 directed to tile D4.

Output of D3 and E4 arrival makes tile D4 executable. D4 is “A/B” method is known as dividing input 0 by input 1, then puts result to output 0 by Number object. In this case, tile D4 puts (n*(n+1))/2 to output 0 (tile D5).

Note that exchanging input 0 and input 1 of tile D4 makes unexpected result 2/(n*(n+1)). Input 0 must from top and input 1 must from right. Thus arrow numbering is needed for keeping away from this confusion.

Tile D5 ALRT is commanding to input 0 (Number object of SUM), input 0 number token displays alert which displays SUM, and passes input to. D6. Then arrived token is discarded by END – no output FLOW – method commanding of D6. After D6 execution, there is no executable tile, so VPGL executor stops.


Next example shows “User defined” method. You can make your own method definitions for any class naming as you like written by build up definition diagram.

This example also calculates summation of N. but it implements repeating addition from 1 to N. This example introduces user defined method named “SUM” for Number class object at D2.

You can see the definition of SUM by change selection;
Class: to Number
and
Method: SUM.

The Mainline of App is quite simple by introducing SUM method. D2 takes a user input positive integer at D1. VPGL executor feeds input to D2 SUM method commanding tile. the SUM for Number object returns its result to D3 ALRT displaying alert dialog for Number Object. Finally, D4 END discards arrived itself for Number token, then VPGL executor terminates.

Now let’s see the definition of SUM operator grid. This is 5×5 grid, top-center of this grid is C1, bottom-center is C5. This definition of SUM method has 1 input from top of this grid, (top side of C1) and 1 output to bottom of this grid (bottom side of C5). These setting are presented in IN: and OUT: field. See the section “Fire Conditoin Notation” in here(UC)for detail.

For help to your quick check this chart, following list is descriptions of bland new operators:

  • C1, B1, C3 tile are 1-input/2outs FLOW method. It duplicates input-0 object and provides them to output-0 and output 1 for each. This is common action for all objects.
  • GT(UC): B2 tile is GT compare operation for Number objects. It puts *T* symbol(UC) to output 0 if input 0 >(greater than) output 1, puts NIL (UC) to output 0 else (input 0 <(less than) input 1 or input 0 = input 1).
  • SWITCH(UC): C2 tile is conditional branch method command for any objects, as known as putting input 0 to output 0 if input 1 is not NIL, putting input 0 to output 1 else. In both case, another output does not emit any token. SWITCH sees NIL as logical false, anything else as logical true.
  • n-1(TBD): B3 “n-1” is decrement (-1) operation for Number Object as putting the value of (input 0) – 1 to output 0.
  • A+B(TBD) : C4 “A+B” is addition of two numbers operation known for Number Object as known a putting the value of (input 0) + (input 1) to output 0.
  • C5 is 2-in/1-out FLOW method. Such FLOW passes input 0 to output 0 and input 1 to output 0 as soon as either input arriving without waiting another input arriving.

As your know by quick preview of this chart, it implements following logic:

  1. Check (input 0) > 0
  2. if (input 0) is less than or equal 0, Number zero is passed to (output 0) directly through the path C1-C2-D2-D3-D4-D5-C5.
  3. else SUM(n) is calculated by n + SUM(n-1) and the result is passing thru C5.

This implementation uses RECURSIVE CALL technique instead of looping. This definition of SUM uses invoking SUM itself.

Note that SUM is defined for only for Number Object. If user input is not a Number object. “No Such Operation: SUM” error will be reported.


SUMMARY

  • VPGL diagram is a square grid of “Data Flow” chart.
  • Arrows in VPGL diagram represents “Where data to go”, not “What to do next”
  • The method name of each grid are passed to arrived token as input 0 or first arrived token to look for defined action of that arrived object.
  • Each operation tile will get start when data arrival condition stands. Almost operation can get start when “All inputs are arrived”.
  • VPGL executor starts with dropping an object of App class on the top side of “Mainline” method definition grid of App class.
  • VPGL executor tries to find tiles that are able to get start, pick one of them, then execute it over and over.
  • VPGL executor stops if no tile can be executable as the result of finding tiles eligible to execute, or executing STOP method.

You can be a programmer of VPGL by step-by-step examples here (UC).