方案中的这个定义语法宏有什么问题?
我正在研究 SICP,并想尝试一下其中的一些示例。我正在尝试流示例,并想要 cons-stream 的实现,这是我从 这个 StackOverflow 问题。然而,当我在 guile 中输入此内容时,我得到:
guile> (define-syntax cons-stream
(syntax-rules ()
[(cons-stream x y) (cons x (delay y))]))
ERROR: invalid syntax ()
ABORT: (misc-error)
我不知道这有什么问题 - 我尝试用 '() 替换 (),删除 [ ],但它仍然不起作用,即使它看起来是 < a href="http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-ZH-2.html#%_toc_%_sec_4.3.2" rel="nofollow noreferrer">有效的 R5RS 。我目前使用的是 guile 1.8.7,我看不到 v2.0.1 的包 GNU 文档提到,这可能是它对我不起作用的原因吗?
I'm working though SICP and wanted to try out some of the examples in guile. I'm trying the stream examples and wanted an implementation for cons-stream, which I got from this StackOverflow question. However when I type this into guile I get:
guile> (define-syntax cons-stream
(syntax-rules ()
[(cons-stream x y) (cons x (delay y))]))
ERROR: invalid syntax ()
ABORT: (misc-error)
I have no idea what's wrong with this - I've tried replacing () with '(), removing the [ ], but it still doesn't work even though it seems to be valid R5RS. I'm currently on guile 1.8.7, I can't see a package for v2.0.1 which the GNU docs mention, could this be why its not working for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您需要首先导入对
syntax-rules
的支持(请参阅http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Syntax-Rules.html):那么你需要更改方括号到括号;之后它应该起作用。
绝对不要引用文字列表;这是一个标识符序列,如 lambda 形式,而不是表达式。
Looks like you need to import support for
syntax-rules
first (see http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Syntax-Rules.html):Then you need to change the square brackets to parens; after that it should work.
Definitely don't quote the literals list; that's a sequence of identifiers, like
lambda
formals, not an expression.