Skip to content
AgileLogics
5 min read

Exploring the REPL

Prerequisites: Your first program

Run julia with no arguments to start the REPL (Read-Eval-Print Loop). Type an expression, press Enter, and Julia prints its value:

julia> 1 + 2
3

julia> ans * 10
30

julia> x = 5;

julia> x
5
  • ans holds the last result.
  • A trailing ; hides the result.
  • Press Up to recall earlier lines, Tab to autocomplete names, and Ctrl + D (or type exit()) to quit.

The four REPL modes

Typing one special character at the start of an empty line switches mode; Backspace returns to the normal julia> prompt.

Key Prompt What it does
? help?> Shows the documentation for a function or keyword
] pkg> Package manager: add, remove, update packages
; shell> Runs a system shell command
(none) julia> Runs Julia code
help?> println
  println([io::IO], xs...)

  Print (using print) xs to io followed by a newline. If io is not
  supplied, prints to the default output stream stdout.
...

Unicode input

Julia code can use mathematical symbols. In the REPL (and in VS Code), type a LaTeX-like name and press Tab:

julia> \pi<Tab>      becomes   π
julia> \alpha<Tab>   becomes   α
julia> \sqrt<Tab>    becomes   √
α = 0.5
println(π)
println(float(π))
println(√16)
println(2α)
π
3.141592653589793
4.0
1.0

π is stored as an exact mathematical constant, so printing it shows the symbol; float(π) (or any arithmetic with it) gives the number.

If you see a symbol you can't type, paste it after ? in help mode and Julia tells you the Tab sequence for it.

Handy REPL helpers

  • apropos("median") searches the documentation.
  • methods(println) lists the versions of a function.
  • @edit sum(1:3) opens the source code of a function in your editor.
  • varinfo() lists the variables you've defined.