In Ruby, Python, and presumably a bunch of other REPLs, you can refer to the last value with _
:
>> longCalculationIForgotToAssignToAVariable
42
>> foo = _
>> foo
42
How can I do this in the Scala REPL? I'm aware of the .
feature of the REPL:
scala> foo.getBar()
res1: com.stackoverflow.Bar = [Bar]
scala> .getBaz() // calls method on bar
But this doesn't do what I want. Neither does _
, obviously, or I wouldn't be asking:
scala> val foo = _
<console>:37: error: unbound placeholder parameter
How can I do this? Ammonite answers good too, but would love to do this in the vanilla REPL.