typestar

Macros en Julia

@show, @assert y @time — los tres de todos los días.

subs = [12, 18, 9]

# @show prints the expression and its value -- the field notebook.
@show sum(subs)
@show length(subs) * 5

# @assert documents an invariant and fails loudly when it breaks.
@assert all(subs .> 0) "every stack needs at least one sub"

# @time measures a computation right where it runs.
@time total = sum(x^2 for x in 1:10_000)
println("Sum of squares: $total")

Cómo funciona

  1. @show expr imprime el texto de la expresión y su valor.
  2. @assert cond msg falla fuerte cuando el invariante se rompe.
  3. @time mide asignación y tiempo justo donde corre.

Palabras clave y builtins usados aquí

El intento, en números

Líneas
12
Caracteres a escribir
380
Tokens
56
Ritmo de tres estrellas
65 tpm

Al ritmo de tres estrellas de 65 tokens por minuto, este intento toma unos 52 segundos.

Escribe este fragmento

Paso 1 de 3 en Macros y formato; paso 22 de 27 en Fundamentos del lenguaje.

← Anterior Siguiente →