Code: Select all
(defmacro print-mat (mat &key to-file)
`(cond (,to-file
(let ((*print-case* :downcase))
(with-open-file (str ,to-file
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(dotimes (i 4)
(dotimes (j 2)
(format str "~a" (aref ,mat i j))
(format str " "))
(format str "~%")))))
((eq ,to-file nil)
(dotimes (i 4)
(dotimes (j 2)
(format t "~a" (aref ,mat i j))
(princ #\Space))
(princ #\Newline)))
(t nil)))
first I define a matrix like this:
Code: Select all
(defparameter a (make-array '(4 2) :initial-contents
'((1 2)
(3 4)
(5 6)
(7 8))))
Code: Select all
(print-mat a :to-file "/home/w/quicklisp/dists/quicklisp/software/lisp-cv-master/data/data.txt")
Code: Select all
(defun x ()
(print-mat a :to-file "/home/w/quicklisp/dists/quicklisp/software/lisp-cv-master/data/data.txt"))