Skip to content

Instantly share code, notes, and snippets.

@andy1138
Created February 21, 2013 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy1138/5008300 to your computer and use it in GitHub Desktop.
Save andy1138/5008300 to your computer and use it in GitHub Desktop.
LSUG Macro from Feb'13 dojo
package lsug
import scala.language.experimental.macros
import scala.reflect.macros.Context
object Debug {
def error(s:String) = macro error_impl
def error_impl(c: Context)(s: c.Expr[String]): c.Expr[Unit] = {
import c.universe._
val debug = System.getProperty("BOB", "false")
val x = if(debug.equals("true")) reify(println("ERR: " + s.splice)).tree else reify(println("")).tree
println(x)
c.Expr[Unit](Block(x))
}
}
------
package lsug
object Main extends App {
println( "Hello")
Debug.error("This is an error" )
println("End ")
}
@binarytemple
Copy link

import c.universe._ .... was missing this, without import universe from context... no cheeze!

@binarytemple
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment