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
describe_intanddescribe_strare ordinary procs with distinct types.describe :: proc{describe_int, describe_str}is the whole overload set.- Calls dispatch by argument type; nothing joins the group without being listed.
Keywords and builtins used here
importintpackageprocstring
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.
Step 3 of 3 in Procedures, step 9 of 27 in Language basics.