Macros in Julia
@show, @assert and @time — the everyday three.
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")
How it works
@show exprprints the expression text and its value.@assert cond msgfails loudly when the invariant breaks.@timemeasures allocation and elapsed time in place.
Keywords and builtins used here
forin
The run, in numbers
- Lines
- 12
- Characters to type
- 380
- Tokens
- 56
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 52 seconds.
Step 1 of 3 in Macros & formatting, step 22 of 27 in Language basics.