在 Ruby、Python 和可能的其他一些 REPL 中,您可以使用 引用最后一个值_
:
>> longCalculationIForgotToAssignToAVariable
42
>> foo = _
>> foo
42
如何在 Scala REPL 中做到这一点?我知道.
REPL 的功能:
scala> foo.getBar()
res1: com.stackoverflow.Bar = [Bar]
scala> .getBaz() // calls method on bar
但这不符合我的要求。显然也没有_
,或者我不会问:
scala> val foo = _
<console>:37: error: unbound placeholder parameter
我怎样才能做到这一点?Ammonite 的回答也很好,但很想在香草 REPL 中这样做。