Tutorial by Examples

This simple macro annotation outputs the annotated item as-is. import scala.annotation.{compileTimeOnly, StaticAnnotation} import scala.reflect.macros.whitebox.Context @compileTimeOnly("enable macro paradise to expand macro annotations") class noop extends StaticAnnotation { def m...
When a method is defined to be a macro, the compiler takes the code that is passed as its argument and turns it into an AST. It then invokes the macro implementation with that AST, and it returns a new AST that is then spliced back to its call site. import reflect.macros.blackbox.Context object ...
Macros can trigger compiler warnings and errors through the use of their Context. Say we're a particularly overzealous when it comes to bad code, and we want to mark every instance of technical debt with a compiler info message (let's not think about how bad this idea is). We can use a macro that d...

Page 1 of 1