Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are odd names like $read and $iw doing in the reified expression?

Here are some snippets from my Scala prompt. I import the reflection API and try reifying some expressions, as described in the docs here.

scala> import scala.reflect.runtime.{universe => ru}
scala> val str = "Duck I says."

scala> ru.showRaw(ru.reify(println(2)))
res40: String = Expr(Apply(Select(Select(This(newTypeName("scala")), 
    newTermName("Predef")), newTermName("println")), List(Literal(Constant(2)))))

scala> ru.showRaw(ru.reify(str.length))    
res41: String = Expr(Apply(Select(Select(Select(Select(Select(Ident($line4), 
    newTermName("$read")), newTermName("$iw")), newTermName("$iw")), 
    newTermName("str")), newTermName("length")), List()))

I did not expect to see these symbols $line4, $read, and $iw in the second one. What are they and why are they there?

like image 496
Rob N Avatar asked May 10 '13 12:05

Rob N


1 Answers

val str ... in REPL is actually not a locale variable, but a property of some object. See this answer.

Wrap variable definition and reify call with code block like this:

{
  val str = ...
  showRaw{reify {...}}
}
like image 175
senia Avatar answered Nov 08 '22 08:11

senia