typestar

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

  1. typeof reports what inference decided: Int64, Float64, String.
  2. frames::Int = 24.0 asserts and converts in one motion.
  3. const marks module-level values the compiler may rely on.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in Values, step 2 of 27 in Language basics.

← Previous Next →

Variables and types in other languages