gpt4 book ai didi

scala - Reifying 函数实现而不是引用

转载 作者:行者123 更新时间:2023-12-04 19:06:53 24 4
gpt4 key购买 nike

我需要获取 lambda 函数实现的 AST。我被卡住了,因为 reify 对论点起作用,而不是对它的值(value)起作用。

val x = (a: Int) => println("a")
val t = showRaw(reify(thevalueof x)) //something here should change
println(t)

应该打印:
Expr(Function(List(ValDef(Modifiers(PARAM), newTermName("a"), Ident(scala.Int), EmptyTree)), Apply(Select(Select(This(newTypeName("scala")), newTermName("Predef")), newTermName("println")), List(Literal(Constant("a"))))))

我想应该有一个关于拼接的技巧,但我就是无法做到这一点。

最佳答案

目前没有在宏应用程序之外获取程序 AST 的可靠方法(reify 是一个宏,因此它遵守相同的规则)。但是,我们正在试验可能解决此问题的下一代宏引擎:http://scalamacros.org/news/2014/03/02/project-palladium.html .

关于scala - Reifying 函数实现而不是引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22198782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com