The Scala REPL (Video)
Lesson Notes
Introduction: Based on Chapter 8 of Learn Scala 3 The Fast Way! (Book 1: The Adventure Begins)
- REPL acronym (read/evaluate/print/loop)
How to start
It’s currently April, 2023, and this will change at some point:
$ scala-cli repl
-
I start the REPL with a classpath
clear
functionhelp
function
Create variables and expressions
val
is the keyword to create an immutable variable- types:
Int
,String
,Char
,Boolean
,Double
-
res0
,res1
, etc.
Scala is both an FP and OOP language
- type
-1
- instance of
Int
type .[tab]
- has all these methods
- instance of
- type
"foo".tab
- has 254 methods
- type
.to
thentab
(tab completion)
Create and use functions
def double(i: Int): Int = i * 2
val a = 1
val res = double(a)
REPL commands
:reset
:help
-
Quitting
:quit
^d
Show Scastie as an online REPL
Ammonite repl
double
function output is different-1.tab
output is different
$ scala-cli --power repl --amm
Summary
- Showed how to start REPL
- How to create variables
res0
, etc. (creates own variables)- Tab completion
:quit
,ctrl-d
Update: All of my new videos are now on
LearnScala.dev