[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: real vectors

> I would like to write an object that inherits the vector object and
> defines arithmetic with vectors, like vector addition, vector
> multiplication and so on. I defined a lobby slot realVector, but when I
> try to generate new kinds of realVector with copySize, I get the
> message "_Clone:Filler primitive failed". I took a look into the
> programming manual and it says the _Clone:Filler primitive, that is invoked
> from the copySize method, can only applied to vectors.  I could rewrite
> the realVector object so, that it does includes the vector instead of
> inherit it, and redirect all methods like at:, at:Put:, copy, copySize:
> by redirecting the methods to the included object, but I think this is
> not a decent solution.

You need to _Define the object as a copy of an object that already has
a vector part (such as the prototypical vector).

  prototypes _AddSlotsIfAbsent: ( | myVector = () | )
  myVector _Define: vector copy _AddSlots: ( |
      _ parent* = traits myVector.
      ^ someSlot <- 'a'.
  | )

The _Define gives the receiver a vector part because the argument has
one.  The _Clone:Filler: primitive will now work for myVector.