Using REPL
Read-Eval-Print-Loop is an interactive shell or the language shell that provides the functionality to test out pieces of code. Julia provides an interactive shell with a Just-in-Time compiler at the backend. We can give inputs in a line, it is compiled and evaluated, and the result is given in the next line.
The benefit of using the REPL is that we can test out our code for possible errors. Also, it is a good environment for beginners. We can type in the expressions and press Enter to evaluate.
A Julia library, or custom-written Julia program, can be included in the REPL using include
. For example, I have a file called hello.jl
, which I will include in the REPL by doing the following:
julia> include ("hello.jl")
Julia also stores all the commands written in the REPL in the .julia_history
. This file is located at /home/$USER
on Ubuntu, C:\Users\username
on Windows, or ~/.julia_history
on OS X.
As with a Linux Terminal, we can reverse-search using Ctrl + R in Julia's shell. This is a really nice feature as we can go back in the history of typed commands.
Typing ?
in the language shell will change the prompt to:
help?>
To clear the screen, press Ctrl + L. To come out of the REPL press Ctrl + D or type the following:
julia> exit().