方案:模式匹配中神秘的空洞
我正在编写一个名为 annotate 的函数,它使用 match-lambda —— 通常会递归调用注释。这是模式匹配之一:
(`(lambda (,<param1> . ,<params>) ,<stmts>)
`(CLOSURE ENV (,<param1> . ,<params>) (lambda (ENV) ,(map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>))))))
但是,当该模式匹配时,返回的结果是:
'(CLOSURE
ENV
(x)
(lambda (ENV)
((CLOSURE
ENV
(x y)
(lambda (ENV) ((+ x y))))))
#<void>)
具体来说,我无法弄清楚“void”来自哪里。事实上,如果我包含这一行:
,(displayln (map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>))))
它会打印:
((CLOSURE ENV (x y) (lambda (ENV) ((+ x y)))))
特别是没有“void”。
如果有人能告诉我问题是什么,我将不胜感激。
谢谢。
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 (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>))))))
However, when this pattern is matched this is what returns:
'(CLOSURE
ENV
(x)
(lambda (ENV)
((CLOSURE
ENV
(x y)
(lambda (ENV) ((+ x y))))))
#<void>)
Specifically I can't figure out where "void" is coming from. In fact, if I include the line:
,(displayln (map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>))))
it prints:
((CLOSURE ENV (x y) (lambda (ENV) ((+ x y)))))
notably without "void".
If someone could tell me what the problem is it would be greatly appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#
是displayln
的返回值。当没有任何有意义的返回值时,Scheme 和 Racket 的某些实现中的输出函数通常会返回该值。The
#<void>
is the return value fromdisplayln
. Output functions in some implementations of Scheme and Racket usually return that when there is nothing meaningful to return.