[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] 2D array question
Yeah this is one of those weird object-oriented pass-by-reference instead of pass-by-value things. A simpler example:
x = [0];
y = [x,x];
y[0][0] = 1;
y // == [[1],[1]]
Tom
> El 24 feb 2019, a las 5:02 PM, stefanus@xxxxxxxxx escribió:
>
>
>
>> Am 24.02.19 um 22:30 schrieb nick.colvin@xxxxxxxxx:
>> x = Array.fill(8, Array.fill(8, false));
>
> You're filling your outer array with 8 identical arrays, hence, setting
> x[0][0] to true also changes the first element in all other arrays
> (which are really the same array as in x[0]).
>
> Add non-identical arrays like this:
>
> x = Array.fill(8, { Array.fill(8, false) });
>> x[0][0] = x[0][0].not;
>> x.postln; // only x[0][0] is flipped
>>
>> x = Array.fill2D(8, 8, false);
>> x[0][0] = x[0][0].not;
>> x.postln; // only x[0][0] is flipped
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: https://listarc.bham.ac.uk/marchives/sc-users/
> search: https://listarc.bham.ac.uk/lists/sc-users/search/
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/