typestar

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

  1. %9.2f fija ancho y decimales; %b y %x cambian la base.
  2. %v imprime arreglos, bools y runes sin ceremonia.
  3. tprintf formatea sobre el allocator temporal, barrido por free_all.

Palabras clave y builtins usados aquí

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.

Escribe este fragmento

Paso 3 de 3 en La biblioteca core; paso 24 de 27 en Fundamentos del lenguaje.

← Anterior Siguiente →