On 3 April 2012 17:24, Moritz Lenz <mor...@faui2k3.org> wrote:
> You can, very nearly. You just need to write
>
> my @vec is Vector;
>
> because you really want to change the type of the container, not just of the
> contents (my Vector @vec would be an array containing Vector objects).


Another option might be to just use scalar variables to hold vectors:

my Vector $vector;
my Vector @array_of_vectors;

$vector = 1,2,3,4,5;


> class Vector is Array {}
> multi sub infix:<*>(Vector $a, Real $b) {
>    Vector.new( $a.list X* $b );
> }
>
> my @vec := Vector.new(1, 2, 3, 4);
> say @vec.WHAT;
> say @vec * 3;
>
> Output:
>
> Vector()
> 3 6 9 12
>
> Using binding := instead of assignment replaces the array container with a
> Vector object.

Doesn't work for me :-(  For me the last statement gives "12".


> (you can also override the .STORE method of a scalar, but that's a bit
> creepy if you ask me).

Hmm...  So you'd have to mess with the STORE method of *all* scalars
(i.e. not just the Vector() class) ?

Daniel.
-- 
I'm not overweight, I'm undertall.

Reply via email to