core:fmt verbs in Odin
The printf verbs, Go-flavored: %d and %f, binary and hex, and %v for anything.
package main
import "core:fmt"
main :: proc() {
price := 1234.5
stock := 87
// printf verbs are Go-flavored; %v prints anything sensibly.
fmt.printfln("on the shelf: %d tins", stock)
fmt.printfln("invoice: %9.2f", price)
fmt.printfln("in binary: %b, in hex: %x", stock, stock)
fmt.printfln("anything: %v %v %v", [2]int{1, 2}, true, 'G')
// aprintf allocates; tprintf borrows the temp allocator instead.
line := fmt.tprintf("%d @ %.2f", stock, price)
fmt.println("built:", line)
free_all(context.temp_allocator)
}
How it works
%9.2ffixes width and decimals;%band%xchange the base.%vprints arrays, bools, and runes without ceremony.tprintfformats onto the temp allocator, swept byfree_all.
Keywords and builtins used here
contextfree_allimportintpackageproc
The run, in numbers
- Lines
- 19
- Characters to type
- 516
- Tokens
- 116
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 107 seconds.
Step 3 of 3 in The core library, step 24 of 27 in Language basics.