typestar

Procedure groups in Odin

Overloading is explicit: a proc group lists exactly which procedures share a name.

package main

import "core:fmt"

describe_int :: proc(n: int) {
    fmt.println("an integer:", n)
}

describe_str :: proc(s: string) {
    fmt.println("a string:", s)
}

// Overloading is explicit: a proc group lists its members.
describe :: proc{describe_int, describe_str}

main :: proc() {
    describe(42)
    describe("forty-two")
}

How it works

  1. describe_int and describe_str are ordinary procs with distinct types.
  2. describe :: proc{describe_int, describe_str} is the whole overload set.
  3. Calls dispatch by argument type; nothing joins the group without being listed.

Keywords and builtins used here

The run, in numbers

Lines
19
Characters to type
321
Tokens
72
Three-star pace
75 tpm

At the three-star pace of 75 tokens a minute, this run takes about 58 seconds.

Type this snippet

Step 3 of 3 in Procedures, step 9 of 27 in Language basics.

← Previous Next →