Essentially I want to implement the equivalent of this:
Copy code
def eval(e: Expression): AST = e match {
case Literal(value) => q"$value"
case Attribute(name) => q"row.get($name)"
case Add(left, right) => q"${eval(left)} + ${eval(right)}"
}
i
itzik kasovitch
07/30/2022, 7:14 PM
What's the difference between this and Kotlin string interpolation?
g
Gavin Ray
07/30/2022, 7:17 PM
String interpolation happens at runtime
Scala quasi-quotes don't produce a value, but a typed AST you can compile and evaluate
Codegen like this is critical for performance in compilers and expression evaluators like the query engines in databases
Gavin Ray
07/30/2022, 7:18 PM
You also get free optimization by the compiler since the result is an AST and the compiler can further optimize whatever tree is produced if possible