Directivas de formato en Erlang
~s, ~p, ~B, ~.2f: el vocabulario de io:format.
%% io:format directives: ~s strings, ~p terms, ~B integers, ~.2f.
main(_) ->
Operator = "Maud",
Calls = 47,
Uptime = 99.9625,
io:format("~s connected ~B calls~n", [Operator, Calls]),
io:format("Uptime: ~.2f percent~n", [Uptime]),
%% ~p pretty-prints any term, quoting where needed.
io:format("Raw term: ~p~n", [{shift, night, [3, 7]}]),
%% io_lib:format builds the string instead of printing.
Label = io_lib:format("~s-~B", [Operator, Calls]),
io:format("Label: ~s~n", [Label]).
Cómo funciona
~Bimprime enteros;~.2ffija decimales de flotantes.~pimprime bonito cualquier término, con comillas donde toca.io_lib:formatdevuelve el texto en vez de imprimirlo.
El intento, en números
- Líneas
- 15
- Caracteres a escribir
- 481
- Tokens
- 119
- Ritmo de tres estrellas
- 60 tpm
Al ritmo de tres estrellas de 60 tokens por minuto, este intento toma unos 119 segundos.
Paso 2 de 4 en Texto y números; paso 20 de 31 en Fundamentos del lenguaje.