使用 match-lambda 进行模式模式匹配
我正在编写一个名为 annotate 的函数,它使用 match-lambda,通常会递归调用注释。这是模式匹配之一:
(`(lambda (,<param1> . ,<params>) ,<stmts>)
`(CLOSURE ENV (,<param1> . ,<params>) `(lambda (ENV) ,(map annotate ,(list-append `(,<param1> . ,<params>) `(,<stmts>))))))
list-append 只是从它的两个参数中创建新列表。问题是,当此模式匹配时,它会返回类似以下内容的内容:
'(CLOSURE
ENV
(x)
`(lambda (ENV)
,(map
annotate
(<results of list-append>))))
具体来说,“,(map annotate”按字面打印而不是被评估——即使它没有被引用。函数中的其他模式似乎使用完全相同的语法,但没有这个另外,未引用的函数 list-append 执行时没有任何问题
。
I am writing a function called annotate that uses match-lambda, often with recursive calls to annotate. Here is one of the pattern matches:
(`(lambda (,<param1> . ,<params>) ,<stmts>)
`(CLOSURE ENV (,<param1> . ,<params>) `(lambda (ENV) ,(map annotate ,(list-append `(,<param1> . ,<params>) `(,<stmts>))))))
list-append just makes new lists out of its two arguments. The problem is that when this pattern matches it returns something like:
'(CLOSURE
ENV
(x)
`(lambda (ENV)
,(map
annotate
(<results of list-append>))))
Specifically, ",(map annotate" prints literally rather than being evaluated -- even though it is being unquoted. Other patterns within the function appear to use the exact same syntax without this issue. Also, the unquoted function list-append executes with no problems.
Any advice is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您嵌套了反引号:在
CLOSURE
前面有一个反引号,然后在第二个lambda
前面有第二个反引号,中间没有逗号:注意中间的文字反引号你的输出。我认为删除第二个 lambda 之前的反引号可以解决问题。You have nested backquotes: you have one in front of
CLOSURE
and then a second one in front of the secondlambda
without a comma in between: notice the literal backquote in the middle of your output. I think removing the backquote before the secondlambda
will fix the problem.