Created
February 21, 2013 21:12
-
-
Save andy1138/5008300 to your computer and use it in GitHub Desktop.
LSUG Macro from Feb'13 dojo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import c.universe._ .... was missing this, without import universe from context... no cheeze!