方案:match-lambda 语法错误
我正在编写一个函数注释,它经常使用 match-lambda 并递归调用注释。这是其中一个模式和匹配:
(`(,<param> . ,<params> (lambda (,<args>) ,<stmt> . ,<stmts>))
`(CLOSURE ENV ,(append (append `(,<param>) `(,<params>))`(,<args>)) (lambda (ENV) ,(map annotate `(,<stmt> . ,<stmts>)))))
我收到投诉说第一次使用“.”。是非法的——在“param”和“params”之间——但我不明白为什么。这种模式和匹配没有得到任何抱怨,并且看起来与第一个“.”非常相似:
(`(λ (,<param1> . ,<params>) ,<stmt> . ,<stmts>)
`(CLOSURE ENV ,(map annotate `(,<param1> . ,<params>)) (λ (ENV) ,(map annotate `(,<stmt> . ,<stmts>)))))
任何建议都值得赞赏。
谢谢。
I am writing a function annotate that uses match-lambda often with recursive calls to annotate. Here is one of the patterns and matches:
(`(,<param> . ,<params> (lambda (,<args>) ,<stmt> . ,<stmts>))
`(CLOSURE ENV ,(append (append `(,<param>) `(,<params>))`(,<args>)) (lambda (ENV) ,(map annotate `(,<stmt> . ,<stmts>)))))
I am getting a complaint that the first use of "." is illegal -- between "param" and "params" -- but I can't figure out why. This pattern and match doesn't get any complaints and seems very similar with regards to the first ".":
(`(λ (,<param1> . ,<params>) ,<stmt> . ,<stmts>)
`(CLOSURE ENV ,(map annotate `(,<param1> . ,<params>)) (λ (ENV) ,(map annotate `(,<stmt> . ,<stmts>)))))
Any advice is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这 ”。”在Racket和Scheme中用于表示“不正确的列表”;也就是说,不以“空”结尾的缺点对序列。因此,例如,
是 的简写。
“点”用于表示:“我完成了类似列表的部分;这是最终值,使用它而不是“空”。因此,您可以'不要在列表中的任何位置使用点;它必须位于单个最终元素之前,模式中的点位于一堆元素之前,而不仅仅是一个元素
。在这里使用“...”语法,例如:(
实际上,您也可以在 Racket 中使用点作为中缀表示法,但我很确定这不是您想要做的,在这里。)
The "." is used in Racket and in Scheme to represent "improper lists"; that is, sequences of cons pairs that don't end with "empty". So, for instance,
is a shorthand for
The 'dot' is used to mean: "I'm done with the list-like part; here's the final value, use this instead of "empty". For this reason, you can't use the dot just anywhere in the list; it has to be just before a single, final element. In your example, the dot in the pattern precedes a bunch of elements, not just one.
Looking at your example, it looks you want to use the "..." syntax here, e.g.:
(Actually, you can also use dots for infix notation in Racket, but I'm pretty sure that's not what you're trying to do, here.)