Let us program our first "hello world!" example.
You will need to have one of the frameworks up and running. If not already done, go to the main page of pSpaces, choose a framework and follow the instructions to install it.
We will now create a simple program that illustrates the most basic features of spaces in different languages. The complete code of the example in each of the languages can be found here:
We will go through it step by step.
Go
inbox := NewSpace("space")
C#
SequentialSpace inbox = new SequentialSpace();
Java
Space inbox = new SequentialSpace();
Swift
let inbox = TupleSpace(TupleList())
Go
inbox.Put("Hello world!")
C#
inbox.Put("Hello world!");
Java
inbox.put("Hellow world!");
Swift
_ = inbox.put(["Hello World!"])
Go
var message string
t, _ := inbox.Get(&message)
C#
ITuple message = inbox.Get(typeof(string));
Java
Object[] tuple = inbox.get(new FormalField(String.class())
Swift
let tuple = inbox.get([FormalTemplateField(String.self)])
Go
fmt.Println((t.GetFieldAt(0)).(string))
C#
Console.WriteLine(tuple);
Java
System.out.println(tuple[0]);
Swift
print(tuple)
If you got it, you are now ready for more examples :)