Skip to content

Instantly share code, notes, and snippets.

@hexx
Created September 12, 2012 06:38
Show Gist options
  • Save hexx/3704733 to your computer and use it in GitHub Desktop.
Save hexx/3704733 to your computer and use it in GitHub Desktop.
rpscala86-hygiene.scala
import language.experimental.macros
import scala.reflect.macros.Context
object Macros {
def nonHygienicA(): Int = macro MacrosImpl.nonHygienicAImpl
def hygienicA(): Int = macro MacrosImpl.hygienicAImpl
}
object MacrosImpl {
val a = 15
def nonHygienicAImpl(c: Context)(): c.Expr[Int] = {
import c.universe._
c.Expr[Int](Ident(newTermName("a")))
}
def hygienicAImpl(c: Context)(): c.Expr[Int] = {
import c.universe._
reify(a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment