```On Sat, 14 Dec 2002, ts wrote:

G>      a = mm + Matrix[[12]] # p a.class ???
G>      b = Matrix[[12]] + mm # p b.class ???
G>      c = mm + mm           # p c.class ???

class Matrix
def +(m)
case m
when Numeric
#Matrix.Raise ErrOperationNotDefined, "+"
type.Raise ErrOperationNotDefined, "+"
when Vector
#m = Matrix.column_vector(m)
m = type.column_vector(m)
when Matrix
else
x, y = m.coerce(self)
return x + y
end

#Matrix.Raise ErrDimensionMismatch unless row_size == m.row_size and column_size == m.column_size
type.Raise ErrDimensionMismatch unless row_size == m.row_size and column_size == m.column_size

rows = (0 .. row_size - 1).collect {
|i|
(0 .. column_size - 1).collect {
|j|
self[i, j] + m[i, j]
}
}
#Matrix.rows(rows, false)
type.rows(rows, false)
end
end

mm = MyMatrix[ [42] ]
p mm.type		  	# >> MyMatrix
p mm.to_f.type			# >> MyMatrix

p ((mm + Matrix[[12]]).type) 	# >> MyMatrix
p ((Matrix[[12]] + mm).type) 	# >> Matrix
p ((mm + mm).type          ) 	# >> MyMatrix

this is exactly what i was refering to :

all references to 'Matrix.method' from INSIDE instance methods need to
bechanged to 'type.method' and all is well...

MyMatrix + Matrix   -> MyMatrix
Matrix   + MyMatrix -> Matrix

is slightly counterintuitive... but only if you view the additive associtive
property of numbers as universally applicable to objects, which it is of
course *not*.  if one realizes the Object + AnOther is really
Object.+(AnOther) is makes perfect sense.

-a

--

====================================
| Ara Howard
| NOAA Forecast Systems Laboratory
| Information and Technology Services
| Data Systems Group