Scala reflection: what are odd names like $read and $iw doing in the reified expression? -


here snippets scala prompt. import reflection api , try reifying expressions, described in docs here.

scala> import scala.reflect.runtime.{universe => ru} scala> val str = "duck 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 see these symbols $line4, $read, , $iw in second one. , why there?

val str ... in repl not locale variable, property of object. see this answer.

wrap variable definition , reify call code block this:

{   val str = ...   showraw{reify {...}} } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -