I'm just starting out with common features, and I wonder if this is possible (I really hope so!).
I created 3 packages for processing vectors of different lengths: vector2, vector3 and vector4.
Each package has functions that process vectors of this length:
vector2:normalize - for normalizing *vector2s* vector3:normalize - for normalizing *vector3s* etc.
My vectors are typed arrays (for speed and memory usage, as is done for writing games), so vector3:
(make-array 3 :element-type `single-float).
Now I am writing a package called vectors, which will contain common functions for processing any types of vectors.
So, the passing vector: normalize vector3 should return vector3, etc.
I tried this:
(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))
... based on what I saw in question 6083238 , but it is obvious that he specializes only in simple arrays with one float like:
V> (class-of (make-array 4 :element-type `single-float)) #<BUILT-IN-CLASS SB-KERNEL::SIMPLE-ARRAY-SINGLE-FLOAT>
What would be the best way to do this, given that it should be fast, not memory?
Welcome in advance!
source share