liveBook · Manning

Exclamation mark

As explained in Julia as a Second Language

An exclamation mark in a Julia function name conventionally indicates that the function may mutate one of its inputs and is part of the function's name.

In Julia, an exclamation mark is part of a function name and conventionally warns that the function may mutate one of its inputs. Thus, push! and push are different names; Julia provides push!, not push. section 4.7

Growing an array with push!

Create an empty array, then add values with push!: `ys = []; push!(ys, 3); push!(ys, 8)`. The same `ys` array grows after each call, making the mutation visible. section 4.7

Use the convention to make mutation easier to notice:

  • Add ! to names of functions you define when they potentially modify an input. section 4.7
  • Treat the mark as a readability aid: without it, every function call could require checking whether an input changes. section 4.7
push!(xs, x)

Inspect a short REPL sequence showing an array change after each push! call. section 4.7

How Julia as a Second Language covers it

How deep it goes
Defines the naming convention and demonstrates array mutation, but stops short of broader mutation mechanics.
Examples
Uses push!(ys, x), a custom transform function, and REPL steps that grow an initially empty array.
What it assumes
Assumes basic functions and arrays while introducing mutation and functions passed as arguments through compact examples.
What you can do after
Apply Julia's mutation-naming convention and recognize when push! modifies an existing array.
How it connects
Relates function names to mutation, arrays, higher-order functions, and map-style collection processing.

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.