next up previous contents
Next: Compiling and Running HelloWorld Up: Developing SALSA Programs Previous: Writing SALSA Programs

HelloWorld example

The following piece of code is the SALSA version of HelloWorld program:
 
1.  /* HelloWorld.salsa */
2.  module examples;
3.  behavior HelloWorld {
4.    void act( String[] arguments ) {
5.      standardOutput<-print( "Hello" )@ 
6.      standardOutput<-print( "World!" );
7.    }
8.  }
 
   
Let us go step by step through the code of the HelloWorld.salsa program:

The first line is a comment. SALSA syntax is very similar to Java and you will notice it uses the style of Java programming. The module keyword is similar to the package keyword in Java. A module is a collection of related actor behaviors. A module can group several actor interfaces and behaviors. Line 4 starts the definition of the act message handler. In fact, every SALSA application must contain the following signature if it does have an act message handler:
 
void act( String[] arguments )
 
   
When a SALSA application is executed, an actor with the specified behavior is created and an act message is sent to it by the run-time environment. The act message is used as a bootstrapping mechanism for SALSA programs. It is analogous to the Java main method invocation.

In lines 5 and 6, two messages are sent to the standardOutput actor. The arrow (<-) indicates message sending to an actor (in this case, the standardOutput actor). To guarantee that the messages are received in the same order they were sent, the @ sign is used to enforce the second message to be sent only after the first message has been processed. This is referred to as a token-passing continuation (see Section 3.4.1).


next up previous contents
Next: Compiling and Running HelloWorld Up: Developing SALSA Programs Previous: Writing SALSA Programs
Wei-Jen Wang
2007-11-28