typestar

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

  1. station := "Gull Rock" declares and infers in one stroke.
  2. lamp_turns: int = 148 states the type between name and value.
  3. CAUSEWAY_LIMIT :: 9.5 is a compile-time constant — the same :: that binds procs.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in Values, step 2 of 27 in Language basics.

← Previous Next →

Declarations in other languages