Declarations in Odin
Three declaration forms: := infers, a plain : takes a type, :: binds a constant.
package main
import "core:fmt"
main :: proc() {
// := declares and infers; a plain : declares with a type.
station := "Gull Rock"
lamp_turns: int = 148
oil_gallons := 6.5
oil_gallons -= 1.25
// :: binds a compile-time constant -- same operator that binds procs.
CAUSEWAY_LIMIT :: 9.5
fmt.println(station, "turns:", lamp_turns)
fmt.printfln("oil %.2f, limit %v ft", oil_gallons, CAUSEWAY_LIMIT)
}
How it works
station := "Gull Rock"declares and infers in one stroke.lamp_turns: int = 148states the type between name and value.CAUSEWAY_LIMIT :: 9.5is a compile-time constant — the same::that binds procs.
Keywords and builtins used here
CAUSEWAY_LIMITimportintpackageproc
The run, in numbers
- Lines
- 17
- Characters to type
- 399
- Tokens
- 62
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 53 seconds.
Step 2 of 3 in Values, step 2 of 27 in Language basics.