方案中没有空单词的空列表
我正在编写一个递归函数,在基本情况下返回一个空列表。然而,函数的输出在我的列表中显示“空”单词,这是我不想要的。像这样;
(列表(列表'abc)(列表'def)空(列表'ghi))
我怎样才能防止这种情况?谢谢。
I am writing a recursion function returning an empty list in the base case. However the output of functions shows "empty" word in the my list, which I don't want.Like this;
(list (list 'abc) (list 'def) empty (list 'ghi))
How can I prevent this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题可能是因为 Racket 有多种值的打印样式。尝试将其(在语言选择对话框中)更改为“write”或任何名称,这应该使其输出
((abc) (def) () (ghi))
。The problem is probably because Racket has several printing styles for values. Try changing it (in the language selection dialog) to "write" or whatever it's called, which should make it output
((abc) (def) () (ghi))
instead.您在结果中看到的
empty
不是一个“单词”——请注意,它没有被引用。如果您确实期望结果中出现一个空列表,那么看起来您已经得到了一个。您甚至可以检查:The
empty
that you see in the result is not a "word" -- note that it's not quoted. If you do expect an empty list in the result, then it looks like you got one. You can even check for that:在不了解详细信息的情况下,我最好的猜测是
本质上,只需检查结果是否为空列表,如果是,则不要将其放入您要返回的列表中。
Without knowing details, my best guess would be something like
Essentially, just check if the result is the empty list, and if so, don't put it into the list that you're returning.