Los verbos de core:fmt en Odin
Los verbos de printf, sabor Go: %d y %f, binario y hex, y %v para lo que sea.
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)
}
Cómo funciona
%9.2ffija ancho y decimales;%by%xcambian la base.%vimprime arreglos, bools y runes sin ceremonia.tprintfformatea sobre el allocator temporal, barrido porfree_all.
Palabras clave y builtins usados aquí
contextfree_allimportintpackageproc
El intento, en números
- Líneas
- 19
- Caracteres a escribir
- 516
- Tokens
- 116
- Ritmo de tres estrellas
- 65 tpm
Al ritmo de tres estrellas de 65 tokens por minuto, este intento toma unos 107 segundos.
Paso 3 de 3 en La biblioteca core; paso 24 de 27 en Fundamentos del lenguaje.