无法使用:粘贴在Scala 3.0.0 repl中
在Scala 2.x中,我使用:粘贴
用于多行粘贴。我正在使用Scala 3.0.0,并且使用相同的方法会引发错误:
scala> :paste
Unknown command: ":paste", run ":help" for a list of commands
我尝试了以下内容,但是写完代码后我不知道该如何执行:
scala> if (true)
| println("that was true")
| else
| print("false")
|
我在
:粘贴未实施,但也不是真的需要,因为 Scala 3 repl。
支持多行粘贴。
如何在Scala 3中执行多行代码?
更新1:
我通过使用
scala> if (true)
| println("that was true")
| else
| print("false")
| ;
that was true
是否有其他方法来执行多行代码,而无需编写;
?
In Scala 2.x I use :paste
for multi-line pasting. I am using Scala 3.0.0 and using the same approach throws an error:
scala> :paste
Unknown command: ":paste", run ":help" for a list of commands
I tried the following but I don't know how to execute when I'm done writing the code:
scala> if (true)
| println("that was true")
| else
| print("false")
|
I found at https://users.scala-lang.org/t/solved-cannot-use-paste-in-scala3-repl/7587 that
:paste is not implemented but it’s also not really needed because
multi-line pasting is supported by the scala 3 REPL.
How do I execute the multi-line code in Scala 3?
UPDATE 1:
I achieved it by using
scala> if (true)
| println("that was true")
| else
| print("false")
| ;
that was true
Is there another way to execute the multi-line code, without having to write ;
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为您的特定情况编写代码后如何执行,只需在repper中再次按 Enter :
repl中的块
您还可以输入由卷曲括号界定的块(即, {和
}
)。块派上用场,可以在卧室中实现密封特征。让我们尝试定义对象
a
和b
扩展了密封特征lats
:depp将
latver 和
a
,就好像它们位于不同的文件中一样。如果将它们分组在一个块中,情况并非如此:For your particular case, just press Enter again in the REPL:
Blocks in the REPL
You can also enter a block delimited by curly braces (i.e.,
{
and}
) in the REPL. Blocks come in handy for implementing sealed traits in the REPL.Let's try to define the objects
A
andB
that extend the sealed traitLevel
:The REPL treats the definitions of
Level
andA
as if they were located in different files. That isn't the case if you group them inside a block: