Skip to content

Instantly share code, notes, and snippets.

@stephanos
stephanos / gist:3922840
Created October 20, 2012 10:02 — forked from asouza/scala2.10-reflection
Scala 2.10 new Reflection API
import scala.reflect.api._
import scala.reflect.runtime._
import scala.reflect.runtime.Mirror._
object Pimps {
implicit def pimp(str:String) = new {
def test = println("hello")
}
}
@stephanos
stephanos / dyn.scala
Created October 20, 2012 09:57 — forked from bartschuller/dyn.scala
Example of Scala's Dynamic trait as implemented in Scala 2.9.0 with scalac -Xexperimental
class ListBuilder extends Dynamic {
private var res = List[String]()
def applyDynamic(method: String)(args: Any*) = {
val argString = if (args.length>0) "(" + args.mkString(" ") + ")" else ""
res = method + argString :: res
this
}
def result = res.reverse
import language.experimental.macros
import scala.reflect.makro.Context
object MacroSample {
def compiledTime(): String = macro compiledTime_impl
def compiledTime_impl(c: Context)(): c.Expr[String] = {
import c.mirror._
import c.reify