Using the REPL

Last updated on 2025-08-29 | Edit this page

Overview

Questions

  • How to use the REPL?

Objectives

  • Explore basic functionality of input.
  • Learn how to declare variables.
  • Learn about REPL modes.

Entering the REPL


Melissa and her classmates open a terminal and launch julia:

BASH

julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.6 (2025-07-09)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

This is the so-called REPL, which stands for read-evaluate-print loop. The interactive command-line REPL allows quick and easy execution of Julia statements.

Like the terminal, the Julia REPL has a prompt, where it awaits input:

JULIA

julia>
Callout

implicit prompt

Most of the code boxes that follow do not show the julia> prompt, even though it’s there in the REPL. Why?

It’s important to delineate input (what you type) and output (how the machine responds). The prompt can be confusing, so it is excluded. You may assume that any Julia box prepends the prompt on each line of input.

Callout

Visual Studio Code

An alternative to using the REPL through a terminal is to work with Visual Studio Code or its open source altenative VSCodium. VSC is a source code editor for which a julia extension is available. After installing the application, simply click on the “Extension” symbol on the left side and search for julia. Once installed julia remains usable and can be selected as a programming language in new documents.

For further guidance and visual aid, check out the provided video!

Variables


The first thing they try is to perform basic arithmetic operations:

JULIA

1 + 4 * 7.3

OUTPUT

30.2

That works as expected. It is also possible to bind a name to a value via the assignment operator =, which makes it easier to refer to the value later on. These names are called variables.

JULIA

distance = 30.2
distance_x_2 = 2 * distance

OUTPUT

60.4

Melissa notices that assignment also returns the value. She can also check which variables are defined in the current session by running

JULIA

varinfo()

OUTPUT

  name            size summary
  –––––––––––– ––––––– –––––––
  Base                 Module
  Core                 Module
  Main                 Module
  distance     8 bytes Float64
  distance_x_2 8 bytes Float64

Unicode

In Julia, Unicode characters are also allowed as variables like α = 2. Unicode characters can be entered by a backslash followed by their LaTeX name and then pressing tab (in this case \alphatab).

Exiting the REPL

To exit the Julia REPL and return to the terminal shell, you can use the exit function:

JULIA

exit()

Or you can press Ctrl-D (the Ctrl key and the D key together).

REPL Modes


Help Mode

Unfortunately Melissa can’t remember the LaTeX name of ∂ so she copies the character , presses ? for help mode,

JULIA

?

pastes the ∂ character, then presses enter:

JULIA

help?>

OUTPUT

"∂" can be typed by \partial<tab>

Great! This way she can easily look up the names she needs. She gets back to normal mode by pressing backspace.

Challenge

Exploring Julia’s Help Mode

Help mode can also be used to look up the documentation for Julia functions. Use Julia’s help mode to read the documentation for the varinfo() function.

If you are not already in help mode, type ? to enter it. Then write varinfo and press enter.

JULIA

?varinfo

Shell Mode

Another useful mode is the shell mode that can be entered by pressing ;. The prompt has now changed:

JULIA

shell>

Shell mode can be used to issue commands to the underlying shell, but don’t confuse it with an actual shell: special shell syntax like piping won’t work. Like before, hit backspace to get back to the Julia prompt.

Challenge

Hello, shell> (pwd and cd) !

Two commonly used shell commands are pwd (print working directory) and cd (change directory).

  1. Use pwd to find out what is your current working directory.
  2. Type the command cd in shell mode, which by default will bring you to your “home directory”.
  3. Use pwd again. Did you get a different result from before? Why or why not?

JULIA

shell> pwd

JULIA

shell> cd

JULIA

shell> pwd

The working directory is the location from which you launched Julia. To navigate to a different directory, you can use the cd command by entering: cd <directory>. By default, this command will return you to your home directory if a specific directory is not given. If you initially launched Julia from your home directory, the working directory remains unchanged, so the output of the second pwd command will be identical to the first. Conversely, if you were in a different directory when you started Julia, the results of the two pwd commands will differ. You can use cd - to go back to your previous location.

Challenge

Hello, shell> (ls)!

Another useful shell command is ls (list files). Use it to show the contents of your home directory.

JULIA

shell> cd

JULIA

shell> ls

The first cd command will bring you to your home directory. ls will print a list of the files and directorys in your current location.

Challenge

Hello, shell> (nano and cat)!

Use the shell mode to create a file called hello.jl with the nano terminal text editor. Inside that file write the simple hello world program print("Hello World!").

Check the content of the file using cat hello.jl and then run the program using julia hello.jl.

JULIA

;

JULIA

shell> nano hello.jl
shell> cat hello.jl

OUTPUT

print("Hello World!")

JULIA

shell> julia hello.jl

OUTPUT

Hello World!

backspace

Pkg Mode

Finally there is package mode that is entered with ] which is used for package management, which will be covered later on:

JULIA

]

JULIA

pkg>

Again, press backspace to return to the Julia REPL.

include


The include function executes the code from a file in the current context. Let’s modify the previous challenge to illustrate this.

Challenge

Challenge

Edit the file hello.jl to print the value of a variable x with print("Hello, ", x) (use ?print if you’re curious). Define x in the REPL and include hello.jl to use the variable.

JULIA

;

JULIA

shell> nano hello.jl

Type print("Hello, ", x), then save and close the file.

Press backspace to return to the REPL.

JULIA

x = "REPL"

OUTPUT

"REPL"

JULIA

include("hello.jl")

OUTPUT

Hello, REPL

Before we move on let’s delete the file we created:

JULIA

;rm hello.jl
Key Points
  • The REPL will
    • Read the given input
    • Evaluate the given expression
    • Print the result to the user
    • Loop back to the prompt again
  • Pressing ? enters help mode.
  • Pressing ; enters shell mode.
  • Pressing ] enters pkg mode.
  • To exit shell, help or pkg mode, hit backspace.