-
Notifications
You must be signed in to change notification settings - Fork 0
Syntax
Chipen Hsiao edited this page Jun 23, 2022
·
2 revisions
Let's analyze the following code to understand sl
mod com::avsi::main
import std::io
export function entry() -> i32 {
std::io::printStr("Hello World!\n")
return 0
}Line 1: mod com::avsi::main.
-
modis a keyword defining a module. -
mainis the file name of current file andcom::avsiidentifies the name of the package. Concatenate the each part of the module name by::. Details about module will be introduced in the Module part.
Line 2: import std::io. You can import other modules by import. std::io contains some functions about basic input/output
Line 3: export function entry() -> i32. One of the most important syntax in sl.
-
function entry()defined a function calledentry. It's also the entry of the whole program. - Any code inside its curly brackets
{}will be executed. -
exportindicates that the function is externally visible. -
i32is the return type of this function
Line 4: std::io::printStr("Hello World!\n"). Call function printStr to print "Hello World!". the function is under the module std::io
Line 5: return 0. The function entry returns 0.