我是这种语言的新手,几个月后才重新开始使用它,并且有一个相对基本的问题。我对箭头的理解有些困惑 ->
运营商在其中。在 Learn Ballerina By Example 下的示例中基本款Hello World Main
用下面的代码描述:
import ballerina/io;
public function main() {
io:println("Hello, World!");
}
而在
Hello Word Service
例如,代码如下: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);
}
}
}
我的问题在于
Hello Word Service
程序在行var result = caller->respond("Hello, World!");
我来自 C/Python/Java 背景,箭头在这些语言中的每一种都意味着不同的东西。它在芭蕾舞女 Actor 中有什么特别的作用?我试图寻找语法文档,但没有找到。任何指向特定页面的链接也会有所帮助。
提前致谢。
最佳答案
->
Ballerina 中的操作符代表远程交互。根据语言规范:
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 )
有关更多信息,请参阅下面语言规范的“远程交互”部分。
https://ballerina.io/spec/lang/2019R3/#section_7.9
关于syntax - Ballerina 中箭头 -> 运算符的作用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59460463/