Scalaマクロでパラメーター値にアクセスするときのコンパイルの問題に続いて、述語を適用するマクロを定義したいと思います。ステートメント fn = c.eval( pred ) が存在する場合、クライアント コードはコンパイルに失敗し、問題の性質については何も示されません。
def fnInvocation( value : Int, pred : c.Expr[ Int => Boolean ] ): Boolean = fnInvocationImpl
def fnInvocationImpl(c: Context)( value : Int, pred : c.Expr[ Int => Boolean ] ) : c.Expr[Boolean] = {
var fn = x => x % 2 == 0
// fn = c.eval( pred ) // client compilation fails if this line is included
val result = fn( value )
c.literal( result )
}
マクロ内からこれを実行できるようにする必要がありますか?