- You have Julia installed on your computer.
What is the REPL?
When you type something and press enter, Julia will take your input, evaluate it, and print the result, e.g. typing
x = "Hello" and hitting enter will result in:
Julia's REPL has amazing modes that affect how Julia interprets your input. Here are the modes that are built-in:
? ➡ Help Mode 📖
Help Mode does a few things, best seen through example. Type
? to enter Help Mode. Then type
println and press enter.
- The top line displays a fuzzy search of what you searched for. This will help you find items even if you mistype something.
- If your search term matches an existing identifier, the documentation for that identifier will print. In this example our search found the function
Press delete to go back to Julia mode and type
x = 1. Now type
- Your search
xmatches with the
xyou just created. However, there is no documentation available, so a summary of
x(its type information) is printed out instead. We'll talk about types in a future post.
; ➡ Shell Mode 💻
This lets you run shell commands (as if you opened a terminal but didn't start Julia). A benefit of Julia's Shell Mode is that you can interpolate values into a command with
] ➡ Pkg Mode 📦
Pkg Mode lets you run commands with Julia's package manager (we'll cover this in-depth in a future post) . In the previous post we added packages with:
Alternatively, we could have used Pkg Mode and entered
add StatsBase instead 🎉! On a fresh install of Julia 1.6 you'll see something like:
REPL Modes are extendable! 🔌
Julia packages can add their own REPL modes. Some examples are:
Notable REPL Features
Re-Run a Line
- Press the up key to display the previously-run command. Continue pressing up to go through your history.
- Press ctrl-r to activate a search of your history. Begin typing and the most recent line that contains your search will appear. You can continue pressing ctrl-r to move backwards through matching lines in your history and ctrl-s to move forward. If you've only run the commands seen in this and the previous post, typing
xwill then find the
x = 1line you entered earlier. Press enter to choose the matching line.
The Value of the Previous Line
The Julia REPL stores the value of the previous line in a variable called
You can Auto-complete names, file paths, symbols, and emoji.
- Try typing
prinand pressing tab. Your input will change to
- Julia can help you type out file/directory paths when you press tab inside of a string. For example, suppose you have a file at
"/Users/<username>/f"and then tab will autocomplete the
file.csv(if it's the only file/directory that begins with
f). If there are multiple matches, press tab again to display them.
- Try typing
\piand pressing tab. Your input will change to
- Try typing
\:smile:and pressing tab. Your input will change to 😄! Fun fact: This feature was introduced as an April Fool's Day joke but won traction in the Julia community. You can even use emoji as variables! There's no good reason to do this, but it's neat 🙃.
Sometime you may not want to display the return value of a line (e.g. the object prints a wall of text). You can always skip displaying an object by adding
; to the end of a line:
This is a high-level overview of the Julia REPL. It covers the things you'll need to know to get started with the REPL. If you want to go further into the weeds, check out the official docs here.
Next up is First Steps #3: Plots.