开发者

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 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!


(format t "~{~%~{~A~^ ~}~}"  '((1 2 3) (4 5 6) (7 8 9)))

prints

1 2 3
4 5 6
7 8 9
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜