2012-06-16 30 views
6

Tôi nhớ có sự chuyển đổi ở đâu đó để ngăn chặn việc in các kiểu trả về trong Scala REPL, nhưng tôi không thể tìm thấy nó. Tôi đặc biệt quan tâm đến việc thêm công tắc này vào tệp xây dựng sbt. Một cái gì đó như returnTypes in console := false.Loại bỏ các kiểu trả về trong giao diện điều khiển sbt/Scala REPL

Ví dụ: bây giờ tôi có

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() 

và vì những lý do rõ ràng tôi muốn

scala> within(Span(0, 33)) 
res7: Vector() 

Trả lời

5

Câu hỏi của tôi là về cơ bản được nhân đôi bởi this mailing-list question. Dựa trên ý tưởng Rex Kerr, sau đây có thể đi vào 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 
} 
""" 

Nhưng thật không may, vẫn là sau ba REPL thoát lệnh cần phải được thực hiện bằng tay sau khi giao diện điều khiển khởi động và chạy:

:power 
:wrap shortresults 
:silent 
+0

Đó là một lúc trước. https://issues.scala-lang.org/browse/SI-8349 –

Các vấn đề liên quan