Hello World
Create a folder odin_course and a file hello.odin inside it.
package hello
import "core:fmt"
main :: proc() {
fmt.println("Hellope!")
}
You can run the program using the command odin run .
$ odin run .
Hellope!
Explanation
I will give only a quick explanation of each line. Each chapter goes deeper and eventually towards full understanding.
package hello
Declare the package name hello. All odin files should start with a package declaration and all odin files in a folder should have the same package name.
import core::fmt
core is like a standard library of Odin. It contains utilties that we can use in our program. core:fmt Has the fmt.println which we use to print Hellope to the screen.
main :: proc() {
// do something here
}
main is a procedure (or function). It is the entry point of the program. When you run odin run . inside a folder, Odin looks for the main procedure in all files in that folder and runs whatever is inside.
There should be only one main procedure.
Understanding ::
It is used to declare compile time constants. The compiler will copy paste all instances of main with whatever is on the right of ::.
For example:
LUCKY_NUMBER :: 7
main() :: proc() {
fmt.println(LUCKY_NUMBER + 3)
}
The line fmt.println(LUCKY_NUMBER + 3) would be replaced by fmt.println(7 + 3).