如何在方案中的列表中包含“quote”?
我试图在像这样的方案中创建一个列表: (list 'quote 'a) 我希望输出是 (quote a) 但解释器执行引用并且输出是: 'a
我怎样才能编写代码得到预期的输出吗?
I am trying to make a list in Scheme like this: (list 'quote 'a) and I expect the output to be (quote a) but the interpreter excutes the quote and the output is: 'a
How can I write the code to get the expected output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是应该的,因为表达式
'a
是列表(quote a)
的缩写,并且解释器的打印机正在使用该简写来输出。您应该注意,如果您告诉解释器计算'a
,它会打印出不带撇号的a
。如果您尝试取出
(list 'quote 'a)
的部分,您会发现您得到的正是您期望获得的列表:所以总而言之,您是获得预期的输出,而不是预期的表示。如果您确实要求获得输出
(quote a)
,那么您必须查看解释器的文档以查看是否支持。或者您可能必须编写自己的过程来打印列表。That's as it ought to be, since the expression
'a
is an abbreviation for the list(quote a)
, and the interpreter's printer is using that shorthand for its output. You should note that if you tell the interpreter to evaluate'a
, it prints outa
unadorned with an apostrophe.If you try taking out the parts of
(list 'quote 'a)
, you would see that you have exactly the list you expected to get:So in summary, you are getting the expected output, just not the expected representation. If you truly demand that you get as output
(quote a)
, then you have to look into your interpreter's documentation to see if that's supported. Or you might have to write your own procedure to print out lists.您使用的是哪种实现。更改 REPL 打印出 sexp 的方式取决于您方案的实现,以及该实现是否支持以扩展形式写出 sexps。
Which implementation are you using. Changing how the REPL prints out sexps depends on your implementation of scheme, and if the implementation supports writing out sexps in an expanded form.