方案: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 的语法)。请记住,列表的一般形式是(abc . d)
,意思是(cons a (cons b (cons cd)))
。您也许可以使用,@
来匹配列表中间的某些元素,但我对此不确定。The
.
needs to be before the last element in the list (except for some Racket-specific syntax that you are not using). Remember that the general form of a list is(a b c . d)
, meaning(cons a (cons b (cons c d)))
. You might be able to use,@<params>
to match some elements in the middle of a list, but I am not sure about that.