Merging Two Matrixes... in LISP

Posted by abidikgubidik on Stack Overflow See other posts from Stack Overflow or by abidikgubidik
Published on 2010-05-26T22:55:18Z Indexed on 2010/05/26 23:01 UTC
Read the original article Hit count: 181

Filed under:
(defun merge-matrix (matrix-1 matrix-2)
    (if (not (or (eql (matrix-rows matrix-1) (matrix-rows matrix-2)) (null matrix-1) (null matrix-2))) (error "Invalid dimensions."))
    (cond
        ((null matrix-1) (copy-tree matrix-2))
        ((null matrix-2) (copy-tree matrix-1))
        (t (let ((result (copy-tree matrix-1)))
                 (dotimes (i (matrix-rows matrix-1))
                     (setf (nth i result) (nconc (nth i result) (nth i matrix-2))))
                 result))))

(merge-matrix '((3 1) (1 3)) '((4 2) (1 1)))

* - EVAL: variable NULL has no value

I receive an error like that how I can fix the problem, thanks

© Stack Overflow or respective owner

Related posts about lisp