[l-math-devel] thanks for the package and am I doing something wrong?

Mirko Vukovic mirko.vukovic at gmail.com
Thu May 20 15:06:07 UTC 2010


Hello,

First, thanks for the package.  Second, here is a little problem.  I
fixed it, but I wonder if I am doing something wrong.

For starters, this is on clisp 2.47 running on cygwin/windows.

I am doing some vector rotations, and I was getting errors such as
trying to add a number to NIL.

Consider the following:
(let* ((vec (vector 1.0 0.0 0.0))
	   (mat (roll-matrix 3 (/ pi 2))))
      (* mat vec))

I get the following error:

COMMON-LISP:+: NIL is not a number
   [Condition of type SIMPLE-TYPE-ERROR]

I traced the error to the matrix being filled with nil's instead of zeros.

I did two modifications in the code, where I tagged the modifications
as features

In operations.lisp,

(defmethod c* ((lhs matrix) (rhs vector))
  (test-dimensions lhs rhs)
  (let ((result
	 #-clisp (make-vector (matrix-rows lhs))
	 #+clisp (make-vector (matrix-rows lhs)
			     :initial-elements
			     (make-list (matrix-rows lhs)
					:initial-element 0.0))))
    (do-each-matrix-element (el lhs i j)
      (setf (elt result i)
	    (cl:+ (elt result i)
		  (cl:* el (elt rhs j)))))
    result))

and in matrix.lisp

(defun make-identity (size)
  "Creates an size x size identity matrix."
  (let ((matrix
	 #-clisp (make-matrix size size)
	 #+clisp (make-matrix size size
			     :initial-elements
			     (make-list (* size size)
					:initial-element 0.0))))
    (dotimes (i size matrix)
      (setf (matrix-elt matrix i i) 1))))

Thanks,

Mirko




More information about the l-math-devel mailing list