Scheme宏中的任意计算
据说方案宏,至少是语法情况的变化,允许对要转换的代码进行任意计算。然而(无论是在一般情况下还是在我当前正在考虑的特定情况下)这都需要根据递归函数来指定计算。当我尝试这种方法的各种变体时,我得到例如
main.scm:32:71:compile:unboundidentifier in module (在变压器环境中,不包括运行时定义):expand-vars
(实现是球拍,如果重要的话。)
结果似乎是在宏处理之后才能定义命名函数。
我想我可以求助于 Y 组合器,但我认为值得首先问是否有更好的方法?
Scheme macros, at least the syntax-case variety, are said to allow arbitrary computation on the code to be transformed. However (both in the general case and in the specific case I'm currently looking at) this requires the computation to be specified in terms of recursive functions. When I try various variants of this, I get e.g.
main.scm:32:71: compile: unbound identifier in module (in the transformer environment, which does not include the run-time definition) in: expand-vars
(The implementation is Racket, if it matters.)
The upshot seems to be that you can't define named functions until after macro processing.
I suppose I could resort to the Y combinator, but I figure it's worth asking first whether there's a better approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你使用 Racket 的事实很重要——在 Racket 中,有一种叫做“相分离”的东西,这意味着语法级别不能使用运行时函数。例如,这样:
将不起作用,因为
bleh
是在运行时绑定的,不可用于语法。相反,它应该作为内部定义移动
到宏体,或者移动到它自己的模块并使用
(require (for-syntax "bleh.rkt"))
进行要求。Yes, the fact that you're using Racket matters -- in Racket, there is something that is called "phase separation", which means that the syntax level cannot use runtime functions. For example, this:
will not work since
bleh
is bound at a runtime, not available for syntax. Instead, it should beor
or moved as an internal definition to the macro body, or moved to its own module and required using
(require (for-syntax "bleh.rkt"))
.