Power mode of Scala REPL的启用:phase
命令:
:phase <phase> set the implicit phase for power commands
我似乎找不到有关如何使用此命令的文档。例如,假设我设置了parser
编译器阶段
scala> :phase parser
Active phase is now: Parser
哪些 power 命令已受到影响?如何调用这些受影响的电源命令?与:settings -Xprint:parser
有什么区别?
答案 0 :(得分:3)
该命令使您的代码被评估为enteringPhase
,这是通过使用intp.setExecutionWrapper
完成的。您可以使用-Dscala.repl.debug
见证包装。
它包装了REPL的“印刷品”:
lazy val $print: _root_.java.lang.String = $line4.$read.$iw.$iw.$r.phased.atCurrent {
phased
对象仅使调用适应enteringPhase
。
在下面的示例中,您稍后会看到擦除的类型:
scala> global.rootMirror.staticClass("scala.Option").typeSignature
res0: $r.global.Type =
[+A <: <?>]AnyRef
with IterableOnce[A]
with Product
with Serializable {
def <init>(): Option[A]
final def isEmpty: Boolean
final def isDefined: Boolean
final override def knownSize: Int
def get: A
final def getOrElse[B >: A](default: => B): B
final def orNull[A1 >: A](implicit ev: Null <:< A1): A1
final def map[B](f: A => B): Option[B]
final def fold[B](ifEmpty: => B)(f: A => B): B
final def flatMap[B](f: A => Option[B]): Option[B]
def flatten[B](implicit ev: A <:< Option[B]): Option[B]
final def filter(p: A => Boolean): Option[A]
final def filterNot(p: A => Boolean): Option[A]
final def nonEmpty: Boolean
final def withFilter(p: A => Boolean): Option.this.WithFilter
class WithFilter extends AnyRef
final def...
scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res1: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$PolyType
scala> :phase cleanup
Active phase is now: Cleanup
scala> global.rootMirror.staticClass("scala.Option").typeSignature.getClass
res2: Class[_ <: $r.global.Type] = class scala.reflect.internal.Types$ClassInfoType
scala> global.rootMirror.staticClass("scala.Option").typeSignature
res3: $r.global.Type =
Object
with scala.collection.IterableOnce
with Product
with java.io.Serializable {
def <init>(): Option
final def isEmpty(): Boolean
final def isDefined(): Boolean
final override def knownSize(): Int
def get(): Object
[snip]
REPL中的:type
命令不会受到影响,因为它调用了exitingTyper
。