4

I'm new to this language and just started back at it after a few months and have a relatively basic question. I'm having some confusion understanding the arrow -> operator in it. In the examples under Learn Ballerina By Example the basic Hello World Main is described with the code below:

import ballerina/io;

public function main() {
    io:println("Hello, World!");
}

And in the Hello Word Service example, the code is as follows:

import ballerina/http;
import ballerina/log;

service hello on new http:Listener(9090) {

    resource function sayHello(http:Caller caller, http:Request req) {

        var result = caller->respond("Hello, World!");

        if (result is error) {
            log:printError("Error sending response", result);
        }
    }
}

My question lies in the Hello Word Service program in the line

var result = caller->respond("Hello, World!");

I'm from a C/Python/Java background and arrows mean different things in each of these languages. What does it do in Ballerina specifically? I tried to look for the syntax documentation and was unsuccessful in finding it. Any link to the specific page would be helpful too.

Thanks in advance.

Rahul P
  • 2,493
  • 2
  • 17
  • 31

1 Answers1

4

The -> operator in Ballerina represents a remote interaction. According to the language specification:

A remote-method-call-action is depicted as a horizontal arrow from the worker lifeline to the client object lifeline.

remote-method-call-action := expression -> method-name ( arg-list )

Please refer to the "Remote interaction" section of the language specification below for more information.

https://ballerina.io/spec/lang/2019R3/#section_7.9

Chanaka Lakmal
  • 1,112
  • 9
  • 19