Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp Format Procedure Applied to Arrays

I need some help with the format function and arrays.

My objective is to print a 2 dimensional array of N·N integer values as N integers per line. For example:

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

should be printed as

1 2 3 
4 5 6
7 8 9

I couldn't find any documentation on how to use format to print arrays. Can it actually be done, or should I convert my array into a list and use something like:

(format t "~{~%~{~A~^ ~}~}"  list)
like image 691
rfsbraz Avatar asked Feb 25 '23 16:02

rfsbraz


1 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 i j)))
            (format t "~a " cell)))
        (format t "~%")))
like image 93
Oso Avatar answered Mar 08 '23 19:03

Oso