【问题标题】:Is there a macros to see my code in runtime?是否有宏可以在运行时查看我的代码?
【发布时间】:2015-12-27 17:30:12
【问题描述】:

出于调试目的,我想打印传递的参数,例如

def myfunc(arg: MyType) = println(str_macro(arg) + " = " + arg)

我知道,I can define mine own。但是,这件事似乎是标准的。是否由标准库提供?

【问题讨论】:

  • 您知道如果myfunc 本身不是宏,那么arg 的代码会很令人失望吗? - 它只是类似于ValDef(我的猜测),根本不反映您从呼叫站点发送的内容。该信息已消失。

标签: scala debugging macros scala-macros stringification


【解决方案1】:

我认为标准库中没有,但请参阅https://github.com/adamw/scala-macro-debughttps://github.com/vn971/macro-format(您也可以使用show(reify(arg).tree))。请注意,在这种情况下,正如 0__ 所说,arg 的代码将只是 arg

【讨论】:

  • 是的,我们需要QUOTE(arg) 而不是debug_print(arg)
猜你喜欢
  • 2015-03-01
  • 1970-01-01
  • 2011-03-15
  • 2015-01-23
  • 1970-01-01
  • 1970-01-01
  • 2018-07-24
  • 1970-01-01
  • 2011-08-08
相关资源
最近更新 更多