如何漂亮地打印2d数组的内容b?
以下代码仅返回:
#<array:srfi-9-record-type-descriptor>
(require srfi/25)
(require racket/pretty)
(define (board x y)
(make-array (shape 0 x 0 y) 0))
(define b (board 7 7))
(pretty-print b)
也尝试过:
(array-map(lambda(n)(print n))b)...(我试图将其标记为代码,但它不起作用)
但它返回: 0000000000000000000000000000000000000000000000000
打印是否有办法每隔x个字符插入一个新行?
答案 0 :(得分:1)
您可以尝试滚动自己的漂亮打印程序,尝试一下:
(define (pretty-print board)
(for ((i (in-range (array-length board 0))))
(for ((j (in-range (array-length board 1))))
(printf "~a\t" (array-ref board i j)))
(newline)))
例如:
(pretty-print (board 3 3))
0 0 0
0 0 0
0 0 0