https://kotlinlang.org logo
#getting-started
Title
# getting-started
g

Gavin Ray

07/30/2022, 5:34 PM
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
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
i

itzik kasovitch

07/30/2022, 8:55 PM
Got it. Thanks for explaining. Looks interesting.
2 Views