我想創建一個匹配語句使用宏,匹配給定類型的所有子類。 但我在提取案例類的字段值時遇到了問題。 例如: sealed abstract class Foobar
case class Foo(x:Int,f:Foobar) extends Foobar
case class Bar(s:String, f:Foobar) extends Foobar
現在我想創建的代碼看起來像這樣,當Foo
我已經解構功能,得到了它vparams,現在我能夠撥打: case class Action(f: Function, ts: List[TypeName]) {
def render(ruleName: String): Expr[Unit] = c.Expr[Unit](q"""
val p = ${c.prefix}
val value1 = p.value
Quasiquotes是驚人的 - 他們使Scala編寫的宏非常痛苦,而且根據我的經驗,他們幾乎總是像我所期望的那樣工作。最重要的是,它們現在可用於Scala 2.10中的as a plugin。 這個問題是關於我寫入this blog post時遇到的一個小問題。當我能夠找到幾分鐘時,它就在我的清單上,但我想我會在這裏發佈它,以防其他人能夠打敗我,並幫助其他遇到同樣問題的人。 假設我有名字型對列
我正在玩Scala 2.11的新宏特性。我想看看我能做到以下改寫: forRange(0 to 10) { i => println(i) }
// into
val iter = (0 to 10).iterator
while (iter.hasNext) {
val i = iter.next
println(i)
}
我想我也非常接近這個宏: def _