簡體   English   中英

如何在Scala REPL中使用先前表達式的結果?

[英]How to use previous expression's result in Scala REPL?

// when in Scala REPL
scala> 1
res0: Int = 1

如何在另一個表達式中重用一個表達式的結果?

例如:

scala> 1
res0: Int = 1

scala> the_previous_expression + 1
// = 2

您可以通過在下一行查看其REPL輸出(以res開頭的單詞)來重用前一個表達式的結果。

// when in Scala REPL
scala> 1
res0: Int = 1         // <-- res0 is the handle that you can use

例如:

scala> 1
res0: Int = 1

scala> res0 + 1
res1: Int = 2

scala> res1 + 1
res2: Int = 3

// and so on

您還可以將其與其他人一起使用:

scala> () => "hey!" // anonymous function
res0: () => String = $$Lambda$1104/1658578510@6cff61fc

scala> res0()
res1: String = hey

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM