Variables and types in Julia
Bindings need no keyword; the value carries the type.
# Bindings need no keyword; the value carries the type.
targets = 12
exposure = 90.5
object = "M31"
println(typeof(targets), " ", typeof(exposure), " ", typeof(object))
# An annotation on a local asserts and converts.
frames::Int = 24.0
println(frames, " is a ", typeof(frames))
# const marks module-level values the compiler may trust.
const PLATE_SCALE = 1.42
println("Scale: $PLATE_SCALE arcsec/px")
How it works
typeofreports what inference decided: Int64, Float64, String.frames::Int = 24.0asserts and converts in one motion.constmarks module-level values the compiler may rely on.
Keywords and builtins used here
Intconst
The run, in numbers
- Lines
- 14
- Characters to type
- 405
- Tokens
- 67
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 57 seconds.
Step 2 of 3 in Values, step 2 of 27 in Language basics.