在 Racket/Scheme 中这种形式的语法大小写有什么用法
我对有关使用语法案例的文档感到困惑,但是 f
可能意味着什么?
(define-syntax (check stx)
(syntax-case stx ()
[(f (x y))
#'(list 'second: f x y)]))
I am confused by the documentation about the usage syntax-case, but what can f
possibly mean?
(define-syntax (check stx)
(syntax-case stx ()
[(f (x y))
#'(list 'second: f x y)]))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码以一种相当微妙的方式被破坏了。
首先,
产生一个错误: check:错误的语法: check
但问题在于扩展中出现的“f”的使用。要看到这一点,请尝试将其取出:
这评估良好,产生 '(second: 1234 3 4)
那么,为什么第一个失败了?问题是,在您的第一个示例中,
扩展为
但是,这个问题是扩展中的“check”是“check”宏的另一种用法,因此必须进一步扩展,并且第二次展开的形状不正确。
要看到这一点,您可以尝试使用宏步进器扩展您的程序。运行宏步进器,使用下拉菜单选择“标准”宏隐藏,单击“结束-->”按钮,然后返回上一步。
正常的约定是使用下划线“_”作为“不关心”符号来匹配模式中的宏名称,如下所示:
出于好奇:这段代码来自哪里?
This code is broken in a fairly subtle way.
To begin with,
Yields an error: check: bad syntax in: check
The problem, though, is the use of 'f' that appears in the expansion. To see this, try taking it out:
This evaluates fine, producing '(second: 1234 3 4)
So, why does the first one fail? The problem is that in your first example,
expands into
The problem with this, though, is that the 'check' in the expansion is another use of the 'check' macro, and must therefore be further expanded, and this second expansion does not have the right shape.
To see this, you can try expanding your program using the macro stepper. Run the macro stepper, use the pull-down menu to select "Standard" macro hiding, click on the "End-->" button, and then go back one step.
The normal convention is to use the underscore "_" as a "don't care" symbol to match against the name of the macro in the pattern, like this:
Out of curiosity: where does this code come from?