Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the last result in Scala REPL?

In python REPL I can do things like:

>>> [1,2,3,4]
[1, 2, 3, 4]
>>> sum(_)
10

In clojure REPL I can do this:

user=> "Hello!"
"Hello!"

user=> *1
"Hello!"

Is there is something like this in Scala REPL?

like image 261
om-nom-nom Avatar asked Aug 15 '12 15:08

om-nom-nom


People also ask

How do you get to scala REPL?

We can start Scala REPL by typing scala command in console/terminal.

Does scala have REPL?

Scala REPL is a command-line tool for the expression, evaluation, and execution of small code snippets. The acronym REPL stands for “Read-Evaluate-Print-Loop”. Similar to Java Shell, Scala REPL is very useful to newcomers and to those who want to experiment with new libraries or language features.

What does the scala REPL stand for?

The Scala REPL (“Read-Evaluate-Print-Loop”) is a command-line interpreter that you use as a “playground” area to test your Scala code.


1 Answers

Yes, you can use dot notation to refer to the last result:

scala> List(1,2,3,4)
res0: List[Int] = List(1, 2, 3, 4)

scala> .sum
res1: Int = 10
like image 174
om-nom-nom Avatar answered Sep 29 '22 13:09

om-nom-nom