liveBook · Manning

Read-execute-print loop

As explained in Julia as a Second Language

The Julia REPL is Julia's interactive read-evaluate-print loop for entering expressions and viewing their results.

The Julia read-evaluate-print loop (REPL) is an interactive command line for trying expressions and seeing results immediately. Start it by typing `julia` in a terminal, then enter an expression and press Enter. It is useful for experimentation, testing, and debugging without first writing a program. section 2.1 section 1.8

$ julia
              _
  _       _ _(_)_     |  Documentation: https:/ /docs.julialang.org
 (_)     | (_) (_)    |
  _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
 | | | | | | |/ _` |  |
 | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
_/ |\__'_|_|_|\__'_|  |  Official https:/ /julialang.org/ release
|__/                   |

julia> 2 + 3
5

The terminal launches Julia; at the `julia>` prompt, `2 + 3` evaluates to `5`. section 2.1

The prompt works as a calculator for more than arithmetic: try `sqrt(9)`, `sin(pi/2)`, or a function you have defined. As calculations grow, store them in functions and call them again from the REPL. section 2.1 section 2.5.2

A few shortcuts make interactive work easier:

  • Type the start of a function name and press Tab to complete it; press Tab twice to see possible matches. section 2.5.2
  • Type `\pi` and press Tab to enter `π`. Similar completions help write other Greek letters and Unicode characters. section 2.2
  • Use Ctrl-C to interrupt some stuck code and Ctrl-D to exit Julia. section 2.2

Check a variable interactively

Enter `y = 7`, then `y + 2`; the second expression prints `9`. Reassigning an ordinary variable is possible, but redefining a `const` produces a warning, so avoid relying on that behavior. section 2.2

How Julia as a Second Language covers it

How deep it goes
Shows launch, expression evaluation, tab completion, and shortcuts, without detailing the loop's implementation.
Examples
Uses arithmetic and mathematical function calls, function-name completions, and variable assignments at the `julia>` prompt.
What it assumes
Assumes Julia is installed and configured, then teaches how to launch the REPL and enter an expression.
What you can do after
Operate the Julia REPL to try expressions, inspect results, complete names, and interrupt or exit a session.
How it connects
Connects interactive evaluation to functions, tab completion, Unicode identifiers, variables, and constants.

Also explained in

Compare how 6 books explain read-execute-print loop →

Related concepts

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.