# Common Lisp：专门研究数组长度的泛型函数(Common Lisp: Generic Function Specializing on Array Length)

```vector2:normalize - for normalizing *vector2s* vector3:normalize - for normalizing *vector3s* etc. ``` ```(make-array 3 :element-type `single-float). ``` ```(defmethod v+1 ((vec-a #.(class-of (make-array 3 :element-type `single-float))) (vec-b #.(class-of (make-array 3 :element-type `single-float)))) (v3:v+1 vec-a vec-b)) (defmethod v+1 ((vec-a #.(class-of (make-array 4 :element-type `single-float))) (vec-b #.(class-of (make-array 4 :element-type `single-float)))) (v4:v+1 vec-a vec-b)) ``` ```V> (class-of (make-array 4 :element-type `single-float)) #<BUILT-IN-CLASS SB-KERNEL::SIMPLE-ARRAY-SINGLE-FLOAT> ```

```(defmethod v+1 ((size (eql 3)) vec-a vec-b) (v3:v+1 vec-a vec-b)) (defmethod v+1 ((size (eql 4)) vec-a vec-b) (v4:v+1 vec-a vec-b)) ``` ```(defmethod v+1 ((size (eql 3)) vec-a vec-b) (assert (= 3 (length vec-a) (length vec-b)) "Vector size mismtach") (v3:v+1 vec-a vec-b)) ``` ```(defmacro v+1* (vec-a vec-b) (once-only (vec-a vec-b) `(if (= (length ,vec-a) (length ,vec-b)) (v+1 (length ,vec-a) ,vec-a ,vec-b) (error "Vector size mismatch")))) ```