Appendix A — Quick-reference

A.1 Types

A list of the inbuilt Julia types used in this book, as well as those from modules we have imported.

A.1.1 Numeric types

UInt8, UInt16, UInt32, UInt64, UInt128
Unsigned integers, consisting of a set number of bits
Int8, Int16, Int32, Int64, Int128
Signed integers, consisting of a set number of bits, the first of which determines positive/negative
BigInt
An exact representation of arbitrarily large signed integer
Bool
A Boolean value, i.e. either true or false
Float16, Float32, Float64
A floating-point number, consisting of a set number of bits
BigFloat
A floating-point number, with a user-defined number of bits
Irrational{s} (typeof(s) == Symbol)
An exact representation of a constant irrational value, usually referred to by variable name s
Rational{T} (T <: Integer)
An exact representation of a rational value, given by numerator and denominator of type T
Complex{T} (T <: Real)
A complex number, with real and imaginary part of type T

A.1.2 Collections of multiple values

Tuple{T₁, T₂, [...]}
A grouping of values, where the first has type T₁, the second type T₂, etc.
Array{T, N} (typeof(N) == Int64)
An N-dimensional collection of values of type T
Vector{T}
An Array with one dimension, and values of type T
Matrix{T}
An Array with two dimensions, and values of type T
UnitRange, StepRange, StepRangeLen, LinRange
Ranges of equally spaced numbers, defined by three of start point, end point, step size, and length
CartesianIndices
A structure which can be iterated over to run through all CartesianIndex values in a given range
Set{T}
An unordered collection of unique values of type T
Dict{K,V}
An unordered collection of keys of type K, where each key has a corresponding value of type V
Pair
A collection of two values, much like a Tuple with two entries. Constructed with =>

A.1.3 Other types

Char
A single UTF-8 encoded character
String
A sequence of characters of arbitrary length, representing text
Symbol
An identifier that can be used as a name in Julia, for naming variables, functions, types, modules, etc.
Expr
A structured collection of instructions, which Julia can evaluate as a program
Function (abstract)
Objects which can be given a Tuple of values, perform a predetermined calculation, and return a result. Also used for macros
ComposedFunction{f₁, f₂} (f₁ <: Function, f₂ <: Function)
A pair of functions to be applied one after the other (f₂ before f₁)
Method
An individual method of a Function, defining an algorithm for particular input types
Base.MethodList
A list of Methods for a Function, output by the function methods
Type{T}
When used in type declarations, x::Type{T} is accepted if and only if x == T
Module
A structure grouping together related variable, function, and type definitions under one name, used for instance by packages
CartesianIndex
An alternate means of indexing Arrays, combining a Tuple of indices for each dimension into one value
RGB (from package Colors)
A colour, represented as red, green, and blue components
IOBuffer
A store of data within Julia, which can be read from or written to
IOStream
An interface between Julia and an external file, allowing for reading and writing operations
CSV.Rows (from package CSV)
A structure which can be iterated over to run through all rows of a .csv file
Plots.Plot (from package Plots)
An object containing plotted data as well as additional attributes customising the display of the plot
Shape (from package Plots)
A polygon, defined by its vertices, to be included in a plot
Exception (abstract)
Objects returned when something has gone wrong in computation. The exact type and parameters help to specify the problem

A.2 Functions

A non-exhaustive list of many of inbuilt Julia functions used in this book.

A.2.1 Numerical functions

+, -, *, /, ^
Common mathematical operators, in order addition, subtraction, multiplication, division, and exponentiation
sqrt, sin, cos, tan, min, max, etc.
Common mathematical functions, often known by the same names as mathematical convention
÷, div
Integer division, i.e. division without remainder
//
Rational division, gives a Rational as an answer
%, mod, rem
Modulo, returns the remainder after division. rem and % are equivalent, mod behaves differently e.g. on negative numbers
complex
Creates a Complex number from its real and imaginary parts
<, , >,
Common inequalities, comparing two values and returning a Bool

A.2.2 Text functions

string
Turns any data into its String representation
*, ^
Concatenation of Strings. * concatenates its input Strings, ^ concatenates one String several times
<, , >,
Compares Strings alphabetically (earlier alphabetically is less), returing a Bool
parse
Interprets a String as a number of a given type
Meta.parse
Interprets a String as code, turning it into an Expr

A.2.3 Conditions

==, ===
Respectively equality (are the values equal) and identicality (are their data exactly the same)
<:
Checks if one type is further down the type tree than another. >: is the inverse (like > to <)
isa
Checks if a value is an instance of a given type
isinteger, islowercase, isabstracttype, etc.
Most functions starting with is check some sort of condition, e.g. is the input an integer
!
Negates its input (so !(false) == true and !(true) == false)
in,
Checks if a value is in a collection
any, all
Respectively, returns true if any or all of the elements of their input are true

A.2.4 Functions on collections

collect
Turns any collection into an Array containing the elements of the collection, organised analogously
length, size
Finds the number of elements in a collection. size splits this by dimension, for multi-dimensional collections
first, last
Finds the first and last elements of a collection, respectively
findfirst, findall, findmin, etc.
Finds the indices of the element(s) of a collection to satisfy a given condition
fill, ones, zeros, trues, falses
Creates an Array where all elements are the same
rand
Creates an Array with random elements
append!, prepend!, insert!, push!
Adds elements to a Vector, Set, or Dict
pop!, popat!, delete!
Removes elements from a Vector, Set, or Dict
splice!
Removes elements from a Vector, and replaces them with others
range
Creates a range of equally spaced numbers, variously one of the subtypes of AbstractRange
eachindex
Creates an object which can be robustly iterated over to run through every element of a collection
, , setdiff
Set operations, particularly for use on the Set type
broadcast
Applies a function elementwise instead of to the collection as a whole
reshape
Reorganises the elements of an Array to a new set of dimensions, of equal size
filter
Applies a function to each element of a collection, and only keeps the elements where the function returns true

A.2.5 Functions on IOs

print, println
Converts data to a String representation, and then sends that to an IO, by default stdout
write
Adds data to an IO
position, seek, skip, seekstart, seekend
Queries or moves the pointer of the IO
truncate
Changes the size of the IO, deleting data or adding zeroes as necessary
read, peek
Copies data from an IO
readeach, readuntil, readline, readlines
Variations on read, in particular useful for reading String data
take!
Clears the data from an IO, returning it as a Vector of UInt8s, i.e. bytes
open, close
Respectively activates and deactivates an IOStream, used for interacting with external files

A.2.6 Introspective functions

typeof
Returns the type of a literal, or the data stored by a variable
bitstring
For a primitive type, gives the sequence of bits which represent a value
codeunits
Lists the codeunits (the values of the bytes) comprising a String
methods
Lists the methods defined for a Function
supertype, subtypes
Lists the immediate parent or children in the type tree of a given type
pwd
Prints the current working directory

A.2.7 Other Base functions

eval
Evaluates an Expr as code
Composes Functions into a ComposedFunction
convert
Changes data between types, if possible
promote
Converts two or more inputs to a single type that can best represent them
promote_type, promote_rule
Defines how different pairings of types will promote
display
Represents the data input in the most concise and descriptive way possible. For instance an Int64 will be displayed as text since that is exactly representative of its value, while a Plot from the package Plots will be displayed as an image
error
Creates and throws an ErrorException
throw
Causes an Exception to occur

A.2.8 Functions from other modules and packages

Pkg.add, Pkg.update, Pkg.remove, etc. (from package Pkg)
Changes the packages installed in the current environment, respectively adding new ones, updating existing ones, or removing existing ones
nlsolve (from package NLsolve)
Solves a non-linear system of equations, as defined by a mutating function
plot, plot! (from package Plots)
Creates a plot (by default a line graph) from the input data. The mutating variant plot! modifies a previous plot
scatter, histogram, heatmap, etc. (from package Plots)
Creates the given kind of plot from the input data
plotattr (from package Plots)
Gives information on the attributes of plots that can be changed
current (from package Plots)
Returns the most recent plot to be modified, used by mutating plot functions if no plot variable is specified

A.3 Macros

@time, @elapsed
Times the input computation. @time prints the time and returns the computation result, @elapsed returns the time and bins the computation result
@doc
Similar to the REPL help mode, returns the docstring of an input function, macro, or type
@assert
Throws an error if the following expression returns anything but true
@which
Returns the Method that would be called by an expression
@.
Adds broadcasting to all functions in an expression
@test, @testset (from module Test)
Runs a test on the input expression, expecting a returned value of true like @assert. @testset combines multiple tests together and summarises the results

A.4 Code blocks

A list of the code blocks defined in Julia

begin
Basic block, simply grouping several lines of code together
if, elseif, else
Checks one or more conditions, and runs different code depending on the outcomes
while
Repeats the same code until a condition is met
for
Iterates over a collection of some kind, repeating the same code with every element in turn
function
Defines a method for a function, with given inputs and given code to run
struct, abstract type, primitive type, mutable struct
Defines a new type, with the variety depending on the wording used
do
Defines an anonymous function, which is then passed as the first argument to the preceding function call
try, catch, else, finally
Runs code, with errors caught, and a potential branching path depending on whether an error occurs or not
quote
Defines an Expr comprising the code within it
module
Defines a module, consisting of the code within it
end
Marks the end of a code block. The most recently started code block is ended first (last in, first out)

A.5 Syntax

A list of the various names and symbols used syntactically in Julia.

()
Parentheses, used in several ways:
  • Encloses Tuples, and correspondingly function inputs
  • Expresses precedence for infix operators or other syntax
[]
Square brackets, used in several ways:
  • Encloses Arrays
  • When following a variable or literal, denotes indexing
  • When used in the REPL, ] enters Pkg mode
{}
Curly braces, used in several ways:
  • When following a type, defines a parametric type
  • When following where, encloses several conditions on variables used in type declaration
,
Comma, used to separate elements in a Tuple or Array. This includes implicit Tuples like x, y = f(4)
.
Full stop, used in several ways:
  • As a decimal separator
  • When following a variable or literal, queries the value of a field
  • When following a function name / preceding an infix operator / used in the macro @., denotes broadcasting
  • As part of ...
;
Semicolon, used in several ways:
  • Separates multiple code statements written on the same line
  • Separates elements in an Array, using multiple changes the dimension of separation
  • When in the Tuple of a method definition, separates positional arguments from keyword arguments
  • When at the end of a statement, suppresses the output to stdout
:
Colon, used in several ways:
  • Defines a Symbol or Expr
  • When between two or three numbers, defines a range of type either UnitRange, StepRange, or StepRangeLen
  • As part of ? : and ::
" "
Double quotation marks, used to enclose a String. """ """ enclose a multi-line String
' '
Single quotation marks, used in several ways:
  • Encloses a Char
  • When following an Array, a single ' performs the conjugate transpose
?
Question mark, used in several ways:
  • When used in the REPL, enters help mode
  • As part of ? :
\
Backslash, used in several ways:
  • As the left division function (x \ y == y / x)
  • When in String literals, begins escape sequences
  • When in an appropriate program (e.g. the REPL, a Julia-compatible IDE, or Pluto), begins tab-completion codes for typing non-ASCII symbols
#
Hash, used to mark the following text as a comment
=
Equals, used in several ways:
  • Assigns a value to a variable name
  • Changes the value of data of a mutable type
  • When following an operator, applies the operator to the current value of a variable, and then stores the answer as the new value of that variable (x += 1)
  • As part of shorthand method definitions (f(x) = 2x + 5)
  • When in the Tuple of a method definition, defines a default value for an input if not specified
  • When used in a function call, gives values to keyword arguments
  • As part of =>, <=, >=
<, >
Less than and greater than, used in several ways:
  • Names of comparison operators, that provide infix alternatives to isless
  • <= and >= are the comparison operators with equality allowed (with aliases )
  • <<, >>, >>> are bit shift operators, which operate on Integers by shifting the digits in their binary representations
  • As part of <:, >:, ->, |>, =>
_
Underscore, used as a thousands separator for large numbers (65_536)
π,
The irrational constants π = 3.1415926535897... and ℯ = 2.7182818284590...
$
Dollar sign, used in Strings and Exprs for interpolation
@
At sign, calls a macro
&&
Short-circuiting AND, evaluates the following statement only if the preceding one returns true
||
Short-circuiting OR, evaluates the following statement only if the preceding one returns false
? :
Ternary operator, evaluates the second statement if the first returns true, otherwise evaluates the third statement
true, false
The Bool (Boolean) values, used by conditionals
in,
Used in for loops to define local variables which iterate through the elements of a collection
break
Stops the most recently started loop prematurely
continue
Stops the current iteration of the most recently started loop prematurely, and moves on to the next
return
Stops a Function’s calculations prematurely and returns the value which follows it
local, global, const
Declares the scope of a variable
->
Defines an anonymous function, with the local variables on the left being inputs, and calculations on the right
|>
Pipe operator, applies the following function to the preceding value
::
Type declaration operator, used in several ways:
  • Asserts that a value has a given type, throws a TypeError if it doesn’t
  • When in the Tuple of a method definition, restricts the type of the inputs to that method
import, using
Brings definitions from other modules into scope
=>
Creates a Pair, with the first value to the left and the second to the right
...
Splat / slurp operator, used in several ways:
  • When in a function call or Array construction, treats elements as individual arguments (splat)
  • When in the Tuple of a method definition, collects any extra arguments into a Tuple (slurp)
stdin, stdout, stderr
Variables defining where inputs, outputs, and errors go by default in Julia

A.6 Modules and packages

A list of the modules and packages that we have used or mentioned in this book. A great deal more are available at https://juliahub.com/ui/Packages.

Pluto
Package for an alternative, web-based environment for Julia, in the form of reactive notebooks
UpdateJulia
Utility package for updating Julia to the latest version
Pkg
Standard library module for package management
LinearAlgebra
Standard library module containing functions and specialised types for numerical linear algebra
NLsolve
Package for solving non-linear systems of equations
Plots
Package for creating graphs from data
Colors
Package for dealing with colours, and creating images
ImageShow, ImageIO
Utility packages for better displaying images
CSV
Package for interacting with .csv files

A.7 Glossary

A list of technical terms used in this book.

Abstract type
A type which serves only as an umbrella term for grouping together other types, and cannot take a value of its own
Anonymous function
A function without a name to use in multiple dispatch, simply a mapping from input values of any type to output values
Arguments
The values which are input into a function or macro
Array comprehension
The means of constructing an Array by an implicit for loop
ASCII
American Standard Code for Information Interchange, historical character-to-number mapping that forms the basis of Unicode. Only concerns ‘common’ characters, including the uppercase and lowercase English alphabet, the digits 0-9, and common English punctuation
Backend
The secondary module that Plots actually uses to turn data into images. Similar structure is used by other
Bit
The smallest unit of data, either a 0 or a 1. Computers store data in this format
Bits type
A type whose data entirely consists of primitive types, meaning that they have a fixed format taking up a fixed number of bits
Block
See Code block
Boolean
Named after George Boole, data that is either true or false
Broadcasting
The application of a function elementwise to a collection, rather than to the collection as a whole
Byte
A group of eight bits, often considered as an eight-digit binary number between 0 and 255, i.e. a UInt8 in Julia. Mostly, computers deal with data byte by byte
Character
A single symbol of text, represented in Julia by the Char type
Code block
A grouping of lines of code together by a structure surrounding them. This structure can have control flow implications, or could define a method or type
Codeunit
A single byte of data from a String
Collection
A single value comprised of many others, for instance a String composed of Chars, or an Array or Tuple composed of its elements
Column-major ordering
The indexing scheme of Julia, which goes down the columns before going across the rows
Comment
Text written in code that Julia ignores, helps human readers to understand the code better
Composite type
A type whose data is stored as a number of named fields, which can be individually accessed, and (if mutable) altered
Composition
Of functions, a single Function combining the action of multiple Functions acting one after another
Comprehension
See Array comprehension
Concatenation
Putting two or more similar collections end to end to create a new longer one
Concrete type
A type which can take a value, the opposite of an abstract type
Condition
A calculation which returns a Bool value, either true or false
Conditional
A structure within code where one section of code is only run if a specified condition is true
Constant
A variable whose value is not expected to change
Constructor
A Function-like object, which shares its name with a type, and is (usually) used to create instances of that type
Control flow
Umbrella term for the mechanisms of changing the order in which code is run, such as conditionals, loops, and exceptions
Conversion
The (sometimes automatic) process of changing the type of a variable, while keeping its data intact
Current working directory
The location in the computer’s files where Julia starts looking from for external files
Data type
See Type
Delimiter
A particular character chosen to mark the end of one piece of data and the start of the next. For instance, in English a space ' ' is used as a delimiter between words, and a full stop '.' between sentences
Docstring
A string placed before a function, macro, or type definition, giving information about usage and functionality. Used by the REPL help mode
Environment
A folder in your files, determining which modules and packages are accessible to you among other things. For instance, Pluto uses a different environment to the REPL, so packages installed in Pluto aren’t immediately available in the REPL
Error
See Exception
Exception
An event occurring when a computation has gone wrong. An error message detailing the problem is returned through stderr
Exponent
Of a floating-point number, the bits determining the position of the (binary) decimal point
Field
A store of data for a composite type, referred to by a predefined name
Function
An object which takes zero or more inputs as a Tuple, calls one of its methods on them, and returns a value
Floating-point number
A format of storing a number which includes an offset for moving the (binary) decimal point, similar to scientific notation. Trades off some significant digits for a wider range of representable numbers
Global
A variable whose scope is the entire module it is defined within
IDE
Integrated development environment, a program made for writing code, generally highly configurable
Immutable type
See Mutable type
Index
A number or other value specifying a particular value from a collection
Indexing
The process of specifying a particular value or subset of values from a collection
Infix
A special syntax afforded to functions like +, //, isa, allowing them to be called with two arguments by placing one to the left and one to the right of the function name
Inner constructor
A constructor method defined in the same block as a type is defined. Has special access to the new function to create instances of the type in question
Instance
Of a type, a value which has that type
Interpolation
Substituting in a different value to the literal written, for instance replacing a variable name with its value. Used in particular in String and Expr literals
Key
The values used as indices in a Dict
Keyword argument
An argument of a function identified by its name in a function call. They are separated from positional arguments by ; in a method definition, and optionally in a function call
Literal
A value in code that is not a variable, instead is explicit data. Examples include numeric literals (2, 4.0), string literals ("Julia"), and array literals ([1, 2]), and many more inbuilt types have literal syntax
Local
A variable whose scope is restricted to a code block
Loop
A structure within code allowing for the same code to be run multiple times successively
Machine epsilon
The difference between 1.0 and the next representable floating-point number. Serves as a measure of the limit of precision of that floating-point format
Macro
Similar to a function, but deals with Exprs and allows parse-time exectution, meaning that code can be systematically altered before running
Mantissa
The bits representing the significant digits of a floating-point number, alternatively significand
Method
A predetermined algorithm taking a number of inputs through a sequence of computations to some output. Always corresponds to a particular function or macro
Method table
The list of methods corresponding to a given function or macro, returned by methods
Module
An object collecting many variables, functions, and types into a cohesive, self-contained structure, which can be imported in from other scripts wholesale
Multiple dispatch
The process used by Julia to pick which method of a function or macro should be used, based on the number and type of its inputs
Mutable type
A type whose data is allowed to be changed without redefining the object. This is less efficient but more flexible than immutable types, where once a value is defined, it cannot be changed
Mutating function
A function which uses the mutability of one of its arguments to alter it, perhaps instead of giving a direct output. Conventionally notated by an ! at the end of the function name, for example pop!
Operator
A function corresponding to a mathematical operator such as +, *, //. Often can use infix syntax for consistency with standard mathematical notation
Outer constructor
A constructor method defined outside the block where its type is defined (just like any other method would be for a function)
Overloading
The act of adding a new method to an existing function from another module
Package
An add-on to Julia, with new features and abilities allowing for more functionality or an easier experience. Generally, but not always, specialised towards a certain goal
Package manager
A system for dealing with packages, including installation, updates, and removal. Julia uses Pkg for this by default, Pluto has its own package manager
Parametric type
A type for which some parameters must be specified for it to take a value. These parameters are usually other types, but can be literals of simple data types
Parsing
The process of a computer understanding text as instructions or data
Pointer
A number referring to a specific location. Used by mutable types to refer to where in the computer’s memory their data is stored, or by IO types to refer to where reading and writing operations will begin
Positional argument
An argument of a function identified by its position (e.g. first argument, second argument, etc.), as opposed to a keyword argument identified by name
Primitive type
A type whose data is stored directly as bits in the computer, which Julia interprets as a value
Promotion
The conversion of two or more inputs to a single type that can best represent them
Range
An instance of one of the subtypes of AbstractRange, representing a sequence of equally spaced numbers
Recursive
A function which, for certain inputs, calculates the answer by calling itself with a different input
REPL
Read-eval-print loop, an interface for giving Julia code to run and getting answers
Scope
The region of code in which a name (either of a variable, function, or type) has a given meaning
Series
A single set of plotted data points, labelled as such in the legend
Short-circuiting
Stopping a calculation early if the answer can be inferred. This is used by && and || in Julia
Significand
See Mantissa
Singleton type
An immutable composite type with no fields, meaning that any instance is indistinguishable from any other
Slurping
Collecting extra inputs to a function into a single Tuple as the final input
Splatting
Emptying out the elements of a collection, for instance in a function call or Array construction
String
A sequence of characters, used by programming languages to represent unformatted text
Subtype
Of an abstract type, the types immediately below it in the type graph. In different contexts, subtype may refer to any types below a given abstract type on the type graph, whether one level down, or several
Supertype
The abstract type immediately above a given type in the type graph. This is the smallest grouping of types that our given type belongs to
Tab-completion
Half-completed keywords can be completed by pressing Tab ⇆. This can alternatively give options if the keyword is ambiguous, and is also used to type non-ASCII symbols
Turing-complete
A property of a language allowing it to do any possible calculation. Due to finite memory, no real system is Turing-complete, so Turing-completeness may alternatively ignore this limitation
Type
A data format, telling Julia how data should be processed and stored. Every piece of data within Julia has a type. Also used by Julia in multiple dispatch, to work out how data should be operated on
Type assertion
A line of code prescribing the type that a value should take. If it doesn’t, an exception occurs
Type declaration
A statement within the Tuple of a method definition, prescribing the type that a value should take. If a value doesn’t meet any type declaration, an exception occurs
Type graph
A structure linking the types in Julia by the abstract types that group them together. Often described as a tree, due to the directional nature with each type having one supertype
Type signature
Of a method, the pattern of types that needs to be matched by the inputs
Type stability
Code that is type stable is written such that putting the same types in will always get the same types out, irrespective of their values. In general, this will not affect whether code works or not, but it can hugely improve efficiency
Type tree
See Type graph
Unicode
Standard character-to-number mapping used near universally by modern software (it’s not just emoji)
UTF-8 encoding
The character-to-number mapping of Unicode altered such that each character maps to a certain byte or bytes of data, in a way that a sequence of such bytes can be unambiguously decoded
Variable
A name referring to a predetermined value. This value may change by assignment, or possibly by mutation for mutable types, and the name can be used in code to refer to whatever value it currently has