Tuesday, June 28, 2016

Hello World in GOAL language

A simple Hello World in GOAL will use three files. 

File empty.pl

The first file is an empty Prolog file, that I will name empty.pl. I am going to talk more about this file in the next steps.

File HelloWorld.mod2g

In the second file, I implement the module for printing the Hello World message. 

use empty as knowledge.
exit=always.

module helloWorld {
 if true then print("Hello world").
}
In Line 1, I indicate the reference file for initializing the agent's knowledge. So, I create an empty file, named empty.pl with no content inside. In the current version of GOAL, it is necessary even if it will be an empty file. 

In Line 2, I indicate that the module must execute once and then terminate its execution. At execution time, the main module is called cyclically, so the exit=always is necessary. Change it to exit=never and see what happens.

In Line 3, I define the name of the module.

In Line 4, I define a rule for printing the Hello World message.   

File HelloWorld.mas2g

Finally, in the third file, I configure the system. 

define tom as agent {
 use HelloWorld as main module.
}

launchpolicy {
 launch tom.
}
In the first three lines, I define an agent named tom that uses the module HelloWorld as its main module. In the last three lines, I inform the system to create and execute one agent tom. 

Final Comments

This version of the Hello World in GOAL was implemented using the GOAL 2.0. You can find more about GOAL at http://ii.tudelft.nl/trac/goal

No comments:

Post a Comment