Dynamic updateDynamic and macros

66 views
Skip to first unread message

Chris Reeves

unread,
Apr 27, 2013, 8:43:11 AM4/27/13
to scala-user
I'm trying to implement updateDynamic as a macro in a trait on scala 2.10.1. There is a matching selectDynamic that works, and, if I change the updateDynamic to a plain println with the given name and value, it works. The macro version, however, gives a "macros cannot be partially applied" error in the repl.

Also, if I change updateDynamic to applyDynamic, the macro version works. Calling updateDynamic manually also works.

Is there a special trick to getting updateDynamic to work as a macro, or have I completely missed something?


Thanks, Chris

Eugene Burmako

unread,
Apr 27, 2013, 8:44:26 AM4/27/13
to Chris Reeves, scala-user
Could you provide an example?


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Chris Reeves

unread,
Apr 27, 2013, 9:11:30 AM4/27/13
to Eugene Burmako, scala-user
This is the smallest example I could come up with:

trait Bippy extends scala.Dynamic {
  def selectDynamic(name: String) = macro Bippy.select
  def updateDynamic(name: String)(value: Any) = macro Bippy.update
  def applyDynamic(name: String)(value: Any) = macro Bippy.update
}
object Bippy {
  import scala.reflect.macros.Context
  def select(c: Context)(name: c.Expr[String]): c.Expr[String] = name
  def update(c: Context)(name: c.Expr[String])(value: c.Expr[Any]): c.Expr[String] = name
}

I hope gmail doesn't mangle it.


Thanks, Chris

Eugene Burmako

unread,
Apr 27, 2013, 9:19:09 AM4/27/13
to Chris Reeves, scala-user
Looks like a bug. Could you please submit it?

In the meanwhile, there's a workaround:

import language.dynamics

trait Bippy extends scala.Dynamic {
  def selectDynamic(name: String) = macro Bippy.select
  def updateDynamic(name: String) = Dingus
}
object Dingus {
  def apply(value: Any) = macro Bippy.update

}
object Bippy {
  import scala.reflect.macros.Context
  def select(c: Context)(name: c.Expr[String]): c.Expr[String] = name
  def update(c: Context)(value: c.Expr[Any]): c.Expr[String] = ??? // c.prefix will contain the name
}

Chris Reeves

unread,
Apr 27, 2013, 10:37:31 AM4/27/13
to Eugene Burmako, scala-user


Thanks, Chris
Reply all
Reply to author
Forward
0 new messages