I learned how to splice expr in quotes now. But I didn't find how to splice multiple exprs in a quote. I have a selectable trait and a macro impl function:
trait StructuralTypeRoot extends Selectable
def macroImpl(using q: Quotes): Expr[Any] = {
val exprs: Vector[Expr[Any]] = Vector(
'{def f = 1},
'{def g = 2}) /*make some method def exprs here*/
'{
new StructuralTypeRoot{
${exprs} // can't do this. How can i splice exprs here
}
}
}
Seq
(orVector
) ofExpr
s. You might have to do some lower-level stuff with theQuotes
instance. – Nagana;
. For example, you can write:val combinedExpression : Expr[Any] = exprs.reduce((a, b) => '{$a;$b})
In this way,combinedExpression
is an Expr[Any] (not aVector
). BTW I don't know if it is possible to do what you want with splicing, namely adding method to an anonymous object. – Olsewskinew StructuralTypeRoot { ${expr} }
? Have you already tried with a single expression?? – Olsewskiqouted.reflect.*
. – Olsewski