Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Created April 3, 2015 01:06
Show Gist options
  • Save mpilquist/d4d24e6bf45d1f4f2b8e to your computer and use it in GitHub Desktop.
Save mpilquist/d4d24e6bf45d1f4f2b8e to your computer and use it in GitHub Desktop.
Non-working macro for scoping implicits
def local[A](implicits: Any*)(f: => A): A = macro localMacro[A]
def localMacro[A](c: Context)(implicits: c.Expr[Any]*)(f: c.Expr[A]): c.Expr[A] = {
import c.universe._
val implicitVals = implicits.map { imp =>
val name = TermName(c.freshName())
q"implicit val $name = $imp"
}
c.Expr[A](q"{ ..$implicitVals; $f }")
}
@xeno-by
Copy link

xeno-by commented Apr 3, 2015

Discussion: https://twitter.com/mpilquist/status/583798342565634048. Please leave comments there, because gists don't support notifications, and we will most likely be unable to respond to you here.

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