gpt4 book ai didi

scala - 抑制 sbt 控制台/Scala REPL 中的返回类型

转载 作者:行者123 更新时间:2023-12-04 15:14:16 26 4
gpt4 key购买 nike

我记得在 Scala REPL 中某处有一个开关可以禁止打印返回类型,但我找不到它。我对将此开关添加到 sbt 构建文件特别感兴趣。类似 returnTypes in console := false .

例如。我现在有

scala> within( Span( 0, 33 ))
res7: scala.collection.immutable.IndexedSeq[(de.sciss.lucre.expr.SpanLike, scala.collection.immutable.IndexedSeq[(de.sciss.lucre.expr.Expr[de.sciss.lucre.stm.InMemory,de.sciss.lucre.expr.SpanLike], de.sciss.lucre.expr.Expr[de.sciss.lucre.stm.InMemory,Long])])] = Vector()

出于显而易见的原因,我想要
scala> within( Span( 0, 33 ))
res7: Vector()

最佳答案

我的问题基本上反射(reflect)在 this mailing-list question .基于 Rex Kerr 的想法,以下可以进入 build.sbt :

initialCommands in console := """// helper method to disable type printing
def shortresults[T](t: => T) = {
val s = t.toString
val name = s.takeWhile(_ != ':')
val idx = s.indexOf(" = ")
val full = if (idx >= 0) name + s.substring(idx) else s
val short = if (full.length>799) full.substring(0,796)+"..." else full
print(short)
t
}
"""

但遗憾的是,在控制台启动并运行后,仍然需要手动执行以下三个 REPL 转义命令:
:power
:wrap shortresults
:silent

关于scala - 抑制 sbt 控制台/Scala REPL 中的返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11066289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com