The Code Repository

Getting the Code

I’ve put some of the programs from the book into a registry devoted to Practical Julia code samples. For convenient access, just do
registry add git://
from package mode in the Julia REPL. After adding the registry, you can add any package listed below by entering package mode in the Julia REPL and typing add PACKAGE, substituting the package name shown in boldface. Then, as usual, back in the normal REPL mode, just say using PACKAGE to get access to the module. Many of the modules do not export names, so you will need to namespace them. In the REPL, you can type the name of the package followed by a dot, and then press TAB to see all the available functions (usually only one per package).

If you prefer to download the code outside of the package system, you can use Git directly. Go to the directory where you want to put the code and enter
git clone git://
For example, to download the first package listed below, enter git clone git:// You’ll find the actual module file within the src directory inside the package directory that appears if the git clone command works.

About This Code

These programs are teaching devices, not “production code”. Most of them can be made faster and improved in various ways. All the code in the registry is MIT licensed. Feel free to reuse, including placing into Github or anywhere else that you find convenient. The “canonical” versions will, however, always remain in this repository.

How to Contribute

If you have ideas or improvements that you feel might be useful for other learners, you can contribute patches by email. See these general instructions for the procedure.

Less formally, you can just email me a diff file, or another description of your suggestions. And of course, as mentioned above, you may also maintain your own forks.

The Packages

Chapter 2: Language Basics

BetterStringDecorator: A tiny program that provides a festive version of a string.

Chapter 4: The Plotting System

Gingerbread: This package collects several fragments in this chapter to create a little function that you can call to draw a scatter plot of the iterated map called the “Gingerbread Man”. After importing the package, simply enter draw_gingerbread(a, x₀, y₀, N) to create the picture. Interesting results can be had for values of the parameter 0 < a < 2.

Chapter 5: Collections

Nprimes: The continue statement is illustrated with a small program that generates the first 100 prime numbers. The version in this repository displays the first N primes when you call nprimes(N).

Chapter 6: Functions, Metaprogramming, and Errors

ThreeMacros: The three example macros from this chapter are collected in this package.

Chapter 7: Diagrams and Animations

PlanetDiagram: From Listing 7.1, the function planet_diagram() will use Luxor to draw a diagram of the solar system.

PtolemyJavis: From the “Epicycle Animation” section of the chapter; uses Javis to animate a planet orbiting the Sun in the Ptolemaic style.

DrumheadWithReel: From Listing 7.5, with the addition of one function using Plots’ @gif macro.

Chapter 8: Types

GraphSomeTypes: The program in Listing 8-2, placed in a function. Run to create the diagram.

IsCircleInCircle: The code leading to Figure 8-3. Our circle types, and the is_inside() function for checking if one circle is inside another. The code that draws the diagram is turned into a function that can plot any number of circles.

LeibnizSeries: Using the Leibniz series to estimate π. From the code just before the start of the “Types Aliases” section.

EllipseComplexPlane: Code assembled from the “Parametric Types” section. The Luxor code that creates Figure 8-5 is turned into a function that draws any CEllipse.

WeatherPlotRecipes: Collects all the plotting recipes up to the @userplot section. Call make_weather_plots() to generate the four weather plots.

Chapter 9: Physics

RBCOceananigans: All the code from the “Fluid Dynamics with Oceananigans” section, plus a program to animate the solution.

PlottingUnitsErrors: Publication-quality plots of Unitful arrays. For some mysterious reason the first call to plot_with_units() in this module produces an empty plot sometimes, but subsequent calls work correctly.

ParametricPendulum: Define your desired time function of the string length, and see the resulting pendulum motion. Also includes the Luxor program that draws the diagram of the system.

Chapter 10: Statistics

MontyHall: The “Monty Hall Problem” program, upgraded to use a random number generator and a slightly different style of plot. Contains one function that simulates the problem and draws the plot directly.

PandemicSimulation: From the “Modeling a Pandemic” section. Running the pandemic() function runs the simulation and pops up a live animation of its progress.

Chapter 11: Biology

PreyEvolution: The evolution simulation and visualization functions.

Chapter 12: Mathematics

JmSeries: Calculates the mth Bessel function using the series in Listing 12.2.

Chapter 13: Scientific Machine Learning


ParameterInference: code for Figure 13-12, testing parameter inference for the parametric pendulum.

Chapter 14: Signal and Image Processing

cellCount: Counting cells using the Hough transform.

imageAverager: Smooth pictures with the method that creates Figure 24.

Chapter 15: Parallel Processing

taskTiming: The code that creates Figure 1 in this chapter.