Skip to content

Instantly share code, notes, and snippets.

@markmarch
Created January 6, 2013 09:39
Show Gist options
  • Save markmarch/4466303 to your computer and use it in GitHub Desktop.
Save markmarch/4466303 to your computer and use it in GitHub Desktop.
simple macro use case
import scala.language.experimental.macros
import scala.reflect.macros.Context
/** Trying out macros in Scala 2.10 */
object Macros {
def compiledTime(): String = macro compiledTime_impl
def compiledTime_impl(c: Context)(): c.Expr[String] = {
import c.universe._
val date = c.Expr[String](Literal(Constant(new java.util.Date().toString)))
reify("Compiled at:" + date.splice)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment