Using the REPL
Interactive Scala.
Using the REPL is a free Scala for Backend Engineering & Functional Programming lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Scala for Backend Engineering & Functional Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is the REPL?
The REPL stands for Read-Eval-Print Loop. It is an interactive shell where you type Scala expressions and immediately see their results.
You start it by running scala (or scala-cli repl) in your terminal. It is the fastest way to experiment with the language without writing a whole program.
Your First Expression
Type any expression and press Enter. The REPL evaluates it and prints the result, its type, and a generated name.
For example, typing 1 + 1 shows something like val res0: Int = 2.
object Main {
def main(args: Array[String]): Unit = {
println(1 + 1)
}
}res Variables
Every result you compute is automatically saved into a variable named resN (res0, res1, ...).
You can reuse these names in later expressions, which makes the REPL feel like a running calculator.
object Main {
def main(args: Array[String]): Unit = {
val res0 = 2 + 3
val res1 = res0 * 10
println(res1)
}
}Type Information
One of the most useful features: the REPL tells you the type of every result.
Typing "hello" prints val res0: String = hello. This helps you learn what Scala infers for any expression.
object Main {
def main(args: Array[String]): Unit = {
val greeting = "hello"
println(greeting)
}
}Defining Values
You can define named values inside the REPL using val. They persist for the rest of the session.
Once defined, you can reference them in any later line.
object Main {
def main(args: Array[String]): Unit = {
val pi = 3.14159
val radius = 2.0
println(pi * radius * radius)
}
}Defining Functions
You are not limited to one-liners. You can define functions directly in the REPL and call them right away.
This lets you build up small helpers and test them instantly.
object Main {
def square(x: Int): Int = x * x
def main(args: Array[String]): Unit = {
println(square(5))
}
}Multi-line Input
If you type something incomplete (like an open brace), the REPL shows a continuation prompt and waits for the rest.
This means you can paste or type multi-line definitions naturally without the REPL trying to evaluate too early.
object Main {
def main(args: Array[String]): Unit = {
val total =
1 +
2 +
3
println(total)
}
}Importing in the REPL
You can import anything inside the REPL, just like in a file. This is handy to pull in standard library helpers.
For example import scala.math.* gives you sqrt, abs, and more.
import scala.math.sqrt
object Main {
def main(args: Array[String]): Unit = {
println(sqrt(16.0))
}
}Useful REPL Commands
The REPL has special commands starting with a colon:
:helplists all commands:resetclears your session:quitexits the REPL:type exprshows the type of an expression without running it
Why Use the REPL?
The REPL is perfect for:
- Trying out an unfamiliar API quickly
- Checking what type an expression produces
- Prototyping logic before adding it to a project
- Learning the language interactively
Combining Everything
In a single session you can define values, write functions, import libraries, and chain results together. The REPL keeps all of it in scope.
Here is a small example you could build line by line.
object Main {
def celsiusToF(c: Double): Double = c * 9 / 5 + 32
def main(args: Array[String]): Unit = {
val temps = List(0.0, 25.0, 100.0)
println(temps.map(celsiusToF))
}
}Quick Check
Test your understanding of the Scala REPL.
Recap
You learned that the REPL is an interactive Read-Eval-Print Loop for Scala.
- It prints the value, type, and an auto
resNname for each result - You can define
vals and functions that persist in the session - You can
importlibraries and use multi-line input - Commands like
:type,:reset, and:quitcontrol the session
Frequently asked questions
Is the “Using the REPL” lesson free?
Yes — the full text of “Using the REPL” is free to read here on the web, and the Scala for Backend Engineering & Functional Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Scala for Backend Engineering & Functional Programming course, upgrade to CoddyKit PRO.
What will I learn in “Using the REPL”?
Interactive Scala. You practise Scala for Backend Engineering & Functional Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Scala for Backend Engineering & Functional Programming?
No prior experience is required. Scala for Backend Engineering & Functional Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Using the REPL” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Scala for Backend Engineering & Functional Programming lesson?
Yes. Every Scala for Backend Engineering & Functional Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.