liveBook · Manning

Read-execute-print loop

As explained in Functional Programming in Scala, Second Edition

A read-eval-print loop is an interactive environment that repeatedly reads an expression, evaluates it, prints the result, and prompts for another expression.

A read-eval-print loop (REPL) is an interactive prompt that repeatedly reads an expression, evaluates it, prints its name, type, and value, then prompts for another expression. section 1.3

In Scala, start the interpreter with no arguments, enter expressions at the scala> prompt, paste code directly, or load a source file before trying its definitions. Exit with :quit, Ctrl-D, or Ctrl-C. section 2.1.1

Load and test a definition

Load MyProgram.scala with :load, call MyProgram.abs(-42), and inspect the returned binding: val res0: Int = 42. This short feedback cycle makes the REPL useful for trying code while programming. section 2.1.1

> scala
Welcome to Scala.
Type in expressions for evaluation. Or try :help.
 
scala> :load MyProgram.scala          #1
// defined object MyProgram
 
scala> MyProgram.abs(-42)             #2
val res0: Int = 42                    #3

Shows the complete Scala REPL sequence: start the interpreter, load a file, invoke a definition, and inspect the typed result. section 2.1.1

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Defines the read-evaluate-print cycle and demonstrates loading and calling code, but does not explain interpreter internals.
Examples
Uses string reversal, mutable StringBuilder behavior, source-file loading, and an absolute-value call to illustrate interactive evaluation.
What you can do after
Operate the Scala interpreter to enter expressions, load definitions, inspect typed results, and exit the session.
How it connects
Connects interactive evaluation with Scala expressions, referential transparency, purity, and the substitution model.

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 Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.