Lisp 格式程序
我开始用 Lisp 编程,但在使用 Format 函数时遇到了困难。
我的目标是将整数子列表列表打印为行的 N 个整数。例如:
'((1 2 3)
(4 5 6)
(7 8 9))
应打印为
1 2 3
4 5 6
7 8 9
我尝试在格式化过程中使用迭代,但失败了。
我写的是:
(format t "~{~S ~}" list)
但是这样我得到的子列表是“(1 2 3)”而不是“1 2 3”,所以我尝试了:
(format t "~:{ ~S ~}" list)
这次我进入了子列表,但只打印了第一个元素,所以我介入了并将该函数重写为:
(format t "~:{ ~S ~S ~S ~}" list)
它适用于具有 3 个元素的子列表,但如何使其适用于 n 个元素?
谢谢!
Im starting to program in Lisp and having an hard time with the Format function.
My objective is to print a list of integer sublists as N integers for line. For example:
'((1 2 3)
(4 5 6)
(7 8 9))
should be printed as
1 2 3
4 5 6
7 8 9
I tried using iteration in the format procedure, but I failed.
What I wrote was:
(format t "~{~S ~}" list)
But with this I get the sublists as "(1 2 3)" instead of "1 2 3", so i tried:
(format t "~:{ ~S ~}" list)
this time I got into the sublists but only printed the first element, so I stepped in and re-wrote the function to:
(format t "~:{ ~S ~S ~S ~}" list)
It works for sublists with 3 elements, but how can I make it work for n elements?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
印刷
prints