GETTING "DELETING UNREACHABLE CODE ERROR" USING A DEFMACRO
Posted: Mon May 26, 2014 4:02 am
Here is the macro:
first I define a matrix like this:
;then I can print the matrix to a file at the repl, like this:
The macro works as expected and prints the matrix to a file. If I call it in any function though, as below, I get a deleting unreachable code error. How can I fix my print-mat macro so I can call it in a function
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"))