typestar

Vectors in Julia

1-indexed, growable, and ! marks the mutators.

# Vectors are 1-indexed and grow in place; ! marks mutation.
queue = ["M42", "M45"]
push!(queue, "M31")
println(queue[1], " first, ", queue[end], " last")

# Slices copy; end works inside the brackets.
tail = queue[2:end]
println(tail)

pushfirst!(queue, "Moon")
sort!(queue)
println(queue)
println("Length now $(length(queue))")

How it works

  1. push! appends in place; the bang is a naming convention.
  2. queue[end] indexes from the back; slices like [2:end] copy.
  3. sort! reorders the vector itself.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
329
Tokens
82
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 70 seconds.

Type this snippet

Step 1 of 3 in Collections, step 10 of 27 in Language basics.

← Previous Next →

Vectors in other languages