Skip to content
Chipen Hsiao edited this page Jun 23, 2022 · 2 revisions

Syntax

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.

  • mod is a keyword defining a module.
  • main is the file name of current file and com::avsi identifies 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 called entry. It's also the entry of the whole program.
  • Any code inside its curly brackets {} will be executed.
  • export indicates that the function is externally visible.
  • i32 is 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.

Clone this wiki locally