Functions, short and long in Julia
One-liners define with =; function blocks close with end.
# The short form defines a function in one line.
airmass(alt) = 1 / sind(alt)
# The long form takes a block; return is optional on the last line.
function exposure_plan(target, minutes)
subs = ceil(Int, minutes / 5)
return "$target: $subs subs of 5 min"
end
println(round(airmass(30), digits = 2))
println(round(airmass(90), digits = 2))
println(exposure_plan("Rosette", 47))
How it works
airmass(alt) = 1 / sind(alt)is a full definition.sindworks in degrees — the d suffix family.- The long form takes a block; the last line returns itself.
Keywords and builtins used here
Intendfunctionreturn
The run, in numbers
- Lines
- 12
- Characters to type
- 377
- Tokens
- 77
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 66 seconds.
Step 1 of 3 in Functions, step 7 of 27 in Language basics.