Actor Prolog is well adapted for implementation of different methods of visual programming. Visual languages and diagrams of different types are easily translated into an Actor Prolog text due to high abstraction level of this language.
Recent version of Actor Prolog supports visual programming in terms of SADT (Structured Analysis and Design Technique), also known as IDEF0. To create a source SADT diagram it is possible to use any diagram tools with IDL format support (like BPwin (TM) PLATINUM technology, Inc. or Design/IDEF (TM) Meta Software Corporation). The interpreter translates the SADT diagrams into the Actor Prolog text. Moreover, graphical user interface in an SADT style is created automatically on the basis of source diagrams. This language feature makes it possible creation of visual shells of expert systems, intelligent agents, and other applications.
The support of SADT in Actor Prolog associates with concurrent processes. That is why we start with examples illustrating change of process state and different types of inter-process communication. Let us consider the _Direct1.A example in the SADT directory. Example 1. Transmitting of direct messages between blocks of an SADT model.Let us consider the SADT diagrams. Following SADT rules we included two diagrams in our model. First of them is so-called Context diagram. The second one is so-called Top-Most diagram. Both of the diagrams are stored in the text file _Direct1.IDL that is loaded automatically by interpreter together with the _Direct1.A source file and the _Direct1.DLG file containing dialog box definitions. |
Fig. 1.1. A Context SADT diagram.
The second diagram of the SADT model: |
Fig. 1.2. The Top-Most SADT diagram.
In the Top-Most diagram there are two blocks. The output of the first block is connected to the input of the second one. Consequently, Actor Prolog has to create two processes and guarantee the capability of message transmitting between them. What exactly these processes do and what messages they send each other we will code manually in the _Direct1.A source program. ------------------------------------------- -- An example of Actor Prolog program. -- -- (c) 2002, Alexei A. Morozov, IRE RAS. -- -- Transmitting of direct messages -- -- between blocks of SADT model. -- ------------------------------------------- class 'Sender' specializing 'Dialog': -- entry_o1; value_o1; -- identifier = "Control"; -- text; -- [ goal:-!. -- action("send"):- entry_o1 ? user_message(text). ] ------------------------------------------- class 'Receiver': -- entry_i1; value_i1; -- con; -- [ goal:-!. -- show(_):-!, con ? show. -- Message:- con ? show, con ? writeln( "I have received " "a message:"), con ? set_color('Blue'), con ? writeln(Message), con ? set_color('Black'). ] ------------------------------------------- First of all note that there are neither definitions of processes nor a goal statement in the source program. They will be created as a result of translation of the _Direct1.IDL diagrams definition. In the source program there are only two classes 'Sender' and 'Receiver' that are automatically used in process definitions and linked by necessary communications for data transmission. Note that class names have to be equal to names of blocks of the SADT model. The structure of the 'Sender' and 'Receiver' classes will be considered in detail below. Now we just launch the program and see how it works. |
Fig. 1.3. Visual interface of a SADT style.
Actor Prolog have created automatically a visual interface based on the SADT model of considered program. To enter a diagram block click left mouse button over it. |
Fig. 1.4. Viewing the SADT diagram.
The left mouse button click over the empty space of a diagram invokes closing of this diagram. The right mouse button click over a diagram block shows a comment that was prepared for this block in the source SADT diagram. |
Fig. 1.5. A view of the SADT block comment.
Click the left mouse button over the "Sender" block. The process Sender will open a dialog box in that one should set a text of the message for the "Receiver" block. Enter text of message and press the "Send message" button. The sent message will appear in the text window of the process Receiver. |
Fig. 1.6. Transmitting of direct messages between blocks.
Let us return to the program listing. The 'Receiver' class prints incoming direct messages in the text window. Message:- con ? show, con ? writeln( "I have received " "a message:"), con ? set_color('Blue'), con ? writeln(Message), con ? set_color('Black'). Note that the value of the slot con in the 'Receiver' class is not defined. In the course of translation of the SADT model the value of this slot (a text window, located at the "Receiver" block of the Top-Most diagram) will be defined automatically in corresponding constructor of the instance of the 'Receiver' class. The show predicate of the 'Receiver' class creates this window on the screen. show(_):-!, con ? show. The left mouse button click over a block of visual program interface sends the message show(BlockName) to the corresponding process. Consequently, when clicking over the "Receiver" block of the visual interface, the process Receiver accepts the show message and opens the window con. The 'Sender' class is derived from the predefined 'Dialog' class that implements control of dialog boxes. When clicking over the "Sender" block of the visual interface, the process Sender receives the show message that opens a dialog box according to the definition specified in the _Direct1.DLG file: grid(80,25) -- window_font("Arial",14) diagram_font("Arial",17) dialog_font("Arial",14) -- dialog "Control" ( "Sender control panel", white,blue,default, centered,centered,default) vbox(center) hbox "&Message " edittext(text,10,1,"Hello") end_of_hbox hbox(center) button("send","&Send message") button(close,"&Close dialog") end_of_hbox end_of_vbox end_of_dialog When pressing the "Send message" button of the dialog, the process receives the message action("send") and while handling this message it sends the message user_message(Text) to the slot entry_o1. action("send"):- entry_o1 ? user_message(text). The slot entry_o1 contains a special class instance that dispatch all incoming messages to the diagram blocks connected to the output O1 of the "Sender" block. When translating the SADT model, Actor Prolog automatically creates auxiliary worlds for messaging between blocks and passes them as arguments to corresponding constructors of processes. In SADT there are following notation for block links:
According to these terms, Actor Prolog automatically creates the values of the slots entry_i1-entry_iN corresponding to the inputs, the values of the slots entry_�1-entry_�N corresponding to the controls, the values of the slots entry_o1-entry_oN corresponding to the outputs, and the values of the slots entry_m1-entry_mN corresponding to the mechanisms of each process that implements a block of a program. The program can use this slots for direct messaging via the links of the SADT model. Note that while sending direct messages via the links of the SADT model, an additional argument - a string that denotes the link by which the message was received by the block - is automatically added to the passed predicate. For example, in the considered program an additional "il" argument was added to the user_message predicate. Besides the entry_* slots Actor Prolog creates the value_* slots in the same way. These slots are common variables of processes and are destined for transmitting of flow messages between blocks of the SADT diagram. Particularly, the slots value_i1-value_iN are created for block inputs, the slots value_�1-value_�N are created for the controls, the slots value_o1-value_oN are created for block outputs, and the slots value_m1-value_mN are created for the mechanisms. This type of slots will be used in the next example illustrating transmitting of messages between processes. Example 2. Transmitting of flow messages between blocks of an SADT model.Let us consider the _Flow.A example in the SADT directory. The Top-Most diagram of this example contains two blocks linked by arc of the "output-control" type. |
Fig. 2.1. The Top-Most SADT diagram.
The _Flow1.A source program contains definitions of the 'Sender' and 'Receiver' classes. ------------------------------------------- -- An example of Actor Prolog program. -- -- (c) 2002, Alexei A. Morozov, IRE RAS. -- -- Transmitting of flow messages between -- -- blocks of SADT model. -- ------------------------------------------- class 'Sender' specializing 'Dialog': -- entry_o1; value_o1; -- identifier = "Control"; -- [ goal:-!. ] ------------------------------------------- class 'Receiver' specializing 'Alpha': -- entry_c1; value_c1; -- con; -- [ goal:-!, con ? clear, con ? show, con ? writeln( "I have received " "a value:"), con ? set_color('Blue'), con ? writeln(value_c1), con ? set_color('Black'), -- check(value_c1). -- check(#):-!. check(Value):-!, even(Value). -- show(_):-!, con ? show. ] ------------------------------------------- The 'Sender' class lets choose an integer number from 1 to 5 in a dialog box; then it sends this number to the slot value_o1 (the definition of the dialog box is given below). The 'Receiver' class gets this number from the slot value_�1 and prints it in its text window. Then it checks if the number is even. If the value of the slot value_o1 is even, then the proof of the goal actor succeeds and the process Receiver is switched to the "proven" state. |
Fig. 2.2. Processing of the flow message has succeeded.
Otherwise, the proof of the goal actor fails and the process Receiver is switched to the "failed" state. |
Fig. 2.3. Processing of the flow message has failed.
Note that when the process Receiver is switched to the "failed" state the color of the corresponding block on the screen changes automatically. Actor Prolog automatically changes block color when the state of the corresponding process changes. It is possible to indicate in a file of definitions of dialog boxes what exactly colors should be used for representation of the "proven" and "failed" states. For this purpose the following special commands are used: success_color(MainColor,HatchColor) and failure_color(MainColor,HatchColor), where the argument MainColor is the blocks color and the argument HatchColor is the color of bars (if it has the default value, then there are no bars). The colors of the blocks of the example under consideration is defined in the following way (see the _Flow1.DLG file): grid(80,25) -- window_font("Arial",14) diagram_font("Arial",17) dialog_font("Arial",14) -- success_color(green,default) failure_color(red,white) -- dialog "Control" ( "Sender control panel", white,blue,default, centered,centered,default) vbox(center) vbox(left) radiobuttons(value_o1) radiobutton("Output value = 1") radiobutton("Output value = 2") radiobutton("Output value = 3") radiobutton("Output value = 4") radiobutton("Output value = 5") end_of_radiobuttons end_of_vbox button(close,"&Close dialog") end_of_vbox end_of_dialog Note that the slot value_o1 is indicated directly within a dialog box definition. That is why a number of a radio button chosen by user is sent directly to the output of the "Sender" block. Example 3. Transmitting of flow messages between blocks of an SADT model.Let us consider the _DF1.A example in the SADT directory. This program is a combination of two previous programs. The Top-Most diagram contains three blocks. The "Sender" and "Receiver" blocks are linked with an arc of the "output-input" type, the "Control" and "Receiver" blocks are linked with an arc of the "output-control" type. |
Fig. 3.1. An SADT diagram with three blocks.
Launch the program and see how it works with different parameters entered in the dialog boxes of processes. Note that when the process Receiver is switched to the "failed" state it suspends handling of direct messages. |
Fig. 3.2. Interaction of blocks of an SADT diagram.
Actor Prolog supports all types of links of SADT, including forking and joining arrows. This makes it a powerful tool for rapid prototyping and visual programming of informational systems. |
Table of content |