Lisp Format Procedure
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 li开发者_如何学JAVAne. For example:
'((1 2 3)
(4 5 6) (7 8 9))should be printed as
1 2 3
4 5 6 7 8 9I 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!
(format t "~{~%~{~A~^ ~}~}" '((1 2 3) (4 5 6) (7 8 9)))
prints
1 2 3
4 5 6
7 8 9
精彩评论