public
Created

LSUG Macro from Feb'13 dojo

  • Download Gist
lsug-dojo-feb13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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 ")
}

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.