Lisp formatting procedure applied to arrays

I need help with the format function and arrays.

My goal is to print a 2 dimensional N & middot; N integers as N integers per line. For instance:

 #2A((1 2 3) (4 5 6) (7 8 9)) 

should be printed as

 1 2 3 4 5 6 7 8 9 

I could not find the documentation on how to use format to print arrays. Is it possible to do this, or should I convert my array to a list and use something like:

 (format t "~{~%~{~A~^ ~}~}" list) 
+4
source share
2 answers
 (defun show-board (board) (loop for i below (car (array-dimensions board)) do (loop for j below (cadr (array-dimensions board)) do (let ((cell (aref board ij))) (format t "~a " cell))) (format t "~%"))) 
+4
source

If I'm not mistaken, there is no direct way for format go into an array. You can write your own function that will be used by the tilde-slash ( ~/function/ , see CLHS ), or you can force the array to and use either your directives or ~/pprint-tabular/ . If you want to define your own, CLHS has sample code for pprint-tabular , which you can change for arrays.

+4
source

All Articles