Reading Julia
ISE 754 · a self-test on the Julia in the lectures
Each item shows a few lines of Julia taken from a lecture and asks what one expression evaluates to, or what one line does. Predict first, then pick. The skill being built is reading: the assistant writes the code; the reader's job is to know what it computed, well enough to check it, change a parameter, and try an edge case. Every answer here was computed by running the code, not typed in.
One construct at a time is the faster way in when a particular piece of syntax is the problem. Every row of the syntax card below is numbered; enter that number here, or click it on the card, and the questions are drawn from that construct alone.
The syntax card
Every construct the published lectures use, in the order a reader meets it, with the lecture that introduces it. Reading Julia in this course means recognizing these on sight. Click a number to be quizzed on that construct alone, or type it into the box at the top of the page.
| # | Construct | How to read it | First used |
|---|---|---|---|
| 1 | a = [1, 2, 3] | a vector; commas separate elements | 1.2 Sec. 1.3 |
| 2 | A = [1 2; 3 4] | a matrix; spaces separate columns, ; ends a row | 1.2 Sec. 1.3 |
| 3 | 1:5, 1:2:5, [1:5;] | a range start:stop or start:step:stop; the ; in brackets expands it into a vector | 1.2 Sec. 1.3 |
| 4 | [f(i) for i in 0:5] | an array comprehension: evaluate once per i, collect the results | 1.2 Sec. 1.3 |
| 5 | a[3], a[[2, 4]], a[end] | indexing from 1; an index array picks several; end is the last | 1.2 Sec. 1.3 |
| 6 | A[1, 2], A[:, 1], A[1, :] | row, column; : selects an entire row or column | 1.2 Sec. 1.3 |
| 7 | a[2:end], a[1:end-1] | slices: drop the first, drop the last | 1.2 Sec. 1.3 |
| 8 | 2 .+ a, a .^ 2, f.(a) | the dot broadcasts: apply to each element; 2a needs no dot | 1.2 Sec. 1.4 |
| 9 | sum(a), cumsum(a) | add all elements; the running total | 1.2 Sec. 1.4 |
| 10 | sum(A, dims = 1) | sum down each column (dims = 2: across each row) | 1.2 Sec. 1.4 |
| 11 | a .> 0, .&, .| | a true/false mask, one entry per element; combined elementwise | 1.2 Sec. 1.5 |
| 12 | a[a .> 0], findall(a .> 0) | keep the elements where true; the positions where true | 1.2 Sec. 1.5 |
| 13 | sort, sortperm, argmin | values in order; the indices that sort them; the position of the smallest | 1.2 Sec. 1.5 |
| 14 | t = (6, 1, 4) | a tuple, a fixed group of values, indexed like a vector | 1.2 Sec. 1.6 |
| 15 | function f(a) … return c end | a multi-line function; return hands back the value | 1.2 Sec. 1.7 |
| 16 | f(a) = 3a + 1 | a one-line function | 1.2 Sec. 1.7 |
| 17 | w -> w > 10 | an anonymous function, read “w maps to w > 10” | 1.2 Sec. 1.7 |
| 18 | filter(test, a) | keep the elements for which the test is true | 1.2 Sec. 1.7 |
| 19 | A \ b | left division: solve A x = b | 1.2 Sec. 1.8 |
| 20 | using DataFrames | load a package | 1.2 Sec. 1.9 |
| 21 | DataFrame(x = …, y = …), df.x | a table of named columns; one column back as a vector | 1.2 Sec. 1.10 |
| 22 | x0 = [4.0, 2.0] vs [x0] | in a broadcast, brackets hold a whole vector fixed so it pairs with each element of the other argument | 2.2 |
| 23 | eachrow(P) | the rows of a matrix (or table), one at a time | 2.2 |
| 24 | f(x; dims = 1), round(x, digits = 1) | keyword arguments: named options after the positional ones | 2.2 |
| 25 | c ? a : b | one-line if: a when c is true, else b | 2.2 |
| 26 | c && return x, c && continue | short-circuit: the right side runs only when c is true, so also a one-line if | 2.2, 2.3 |
| 27 | optimize(f, x0).minimizer | the point found by the search that starts at x0; .minimum is the value there | 2.2 |
| 28 | filter(r -> r.POP > 0, df) | keep the rows r of the table for which the test holds | 2.2 |
| 29 | :NC, :POP | a Symbol: a name used as a value, e.g. a state or a column | 2.2 |
| 30 | a, b = 1, 2 | two names assigned at once, left to right | 2.3 |
| 31 | push!(v, x), filter! | the ! warns that the function changes its argument | 1.3, 2.4 |
| 32 | Int[], Float64[] | an empty vector that will hold that type | 1.3, 2.4 |
| 33 | 12e6, 200_000 | 12 × 10⁶; underscores are digit separators for the reader | 2.4 |
| 34 | round(Int, x) | round to the nearest integer, returned as an Int | 2.4 |
| 35 | hcat(lon, lat), vcat | side by side as columns; stacked end to end | 2.5 |
| 36 | :POP => sum => :POP | column => function => new name: a computed column | 2.5 |
| 37 | prt(df) | Logjam's table print, the course's way of showing a table | 2.2 |
| 38 | xᵒ, TCᵒ, σ, tₑ | Unicode is part of the name: ᵒ marks an optimal value; typed by tab completion, x\^o Tab | 1.2 Sec. 1.2 |
Using the assistant as a tutor
For more practice than this page holds, hand any lecture code block (or a whole companion script) to Claude with the prompt below. It turns the assistant into a reading tutor that asks rather than writes; it works in Claude Code or in a chat window.