cmajor-lang/cmajor

Assigning to matrices

remaininlight opened this issue · 2 comments

Have been enjoying exploring matrices but am a bit stuck as to whether they are mutable or not?

I want to assign to a location in the matrix after it’s been instantiated, something like this:

let m = float[2, 3] ((1.0f, 2.0f, 3.0f),
                             (4.0f, 5.0f, 6.0f));
m[1][2] = 7.0f;

This code gives error:

error: Expected an assignable target on the left of the '=' operator
        m[1][2] = 7.0f;
        ^

Can't find any mention of changing matrix values in docs or tests. Would it be possible to do this, am I using the wrong syntax?

Any pointers gratefully received

let declares the variable as a constant - if you change this to 'var' I think your code will work

Wow, yep that works! Thanks :)