Language basics
27 steps in 9 sets of Julia.
Julia is the language built on a refusal: that scientists should not have to prototype in one language and rewrite in another for speed. Born at MIT in 2012, it JIT-compiles dynamic, math-first code to machine speed, and its signature idea — multiple dispatch, where every argument's type picks the method — turns out to be how scientific libraries compose so well. It runs climate models, drug trials, and half of quantitative astronomy.
This tour types the core: bindings and interpolation, ranges and comprehensions, one-line function definitions and multiple dispatch, do blocks, varargs and keyword arguments, 1-indexed vectors with bang-marked mutation, Dicts and named tuples, the broadcasting dot that vectorizes anything, built-in matrices, immutable and parametric structs with abstract-type dispatch, pipes, error handling, and the everyday macros from @show to @printf. The Encore is the cross-language script trio in numeric-flavored Julia — argmin, diff, and Printf columns.
Values
- The script shapeThe smallest Julia: bindings and println, no ceremony at all.
- Variables and typesBindings need no keyword; the value carries the type.
- StringsInterpolation with $, concatenation with *, repetition with ^.
Control flow
- if, elseif and guardsBlocks close with end; && and || double as one-line guards.
- Loops and rangesstart:stop and start:step:stop drive for; while guards.
- ComprehensionsBuild an array from an expression, a range, and an optional filter.
Functions
- Functions, short and longOne-liners define with =; function blocks close with end.
- Multiple dispatchOne function name; the method is chosen by every argument's type.
- Anonymous functions and doArrows for throwaways; do blocks for multi-line arguments.
Collections
- Vectors1-indexed, growable, and ! marks the mutators.
- Dicts and SetsPairs with =>, membership with in, dedup for free.
- Tuples and named tuplesFixed-size bundles, with or without labels.
Broadcasting
- BroadcastingOne dot vectorizes any function or operator.
- map, filter, reduceThe functional trio, plus transforms built into the folds.
- MatricesBuilt-in 2-D arrays: spaces for columns, ; for rows.
Types
- StructsImmutable by default; mutable is a separate promise.
- Abstract typesName the family, dispatch on it, override per concrete type.
- Parametric typesThe T in braces is chosen per use and bounded by <:.
Idioms
- Pipes|> feeds left to right; dotted pipes broadcast the chain.
- Varargs and keywords... collects arguments; keywords live after the semicolon.
- Errorstryparse for expected failure, throw/try/catch for the rest.
Macros & formatting
Encore
- word_freq.jlA word-frequency table from split, a Dict tally, and one sort key.
- grade_report.jlReport cards from a struct roster, guard-clause grading, and vcat.
- temp_stats.jlA week of temperatures: argmin/argmax, a bar chart, and diff.