【发布时间】:2014-08-20 15:53:04
【问题描述】:
使用 Scala 宏我想访问函数 f 的源代码。
这是我的问题的简化示例:
def logFImplementation(f: => Boolean) {
val sourceCodeOfF: String = ... // <-- how to get source code of f??
println("Scala source of f=" + sourceCodeOfF)
}
所以:
logFImplementation { val i = 5; List(1, 2, 3); true }
应该打印出来:
Scala source of f=val i: Int = 5; immutable.this.List.apply[Int](1, 2, 3); true
(现在我测试了Macro to access source code text at runtime,它适用于{ val i = 5; List(1, 2, 3); true }.logValueImpl,但对于f.logValueImpl,它只打印f。)
感谢您的建议。
【问题讨论】:
标签: scala reflection macros scala-macros