assigment of a list type behaves as a reference or hard copy depending on use case
Bug Description
Assigning a list a=list()
to a variable (b=a
) behaves as a reference or hard copy depending on use case.
It seems this behavior is not documented, if normal?
Steps to reproduce
CODE INPUT
// 'Hard-copy' behavior
printf("*********************\n");
printf("Test Hard-copy behaviour\n\n");
a=list([]);
a(1)=[1.123, 6.5454, 9.54];
disp(a);
b=a;
b(1)(2) = 3; // changing b does not modify a
disp(a); // a did not get modified after b was modified
// 'Reference-like' behavior
printf("\n\n*********************\n");
printf("Test Reference-like behaviour\n\n");
a=list([]);
a(1)=[1.123, 6.5454, 9.54];
disp(a);
b=a;
plot2d([0,1],[0,1],b(1)); // a is modified (converted to integer) when b is passed to plot2d()
disp(a);
OUTPUT
*********************
Test normal behavior
(1)
1.123 6.5454 9.54
(1)
1.123 6.5454 9.54
*********************
Test weird behavior
(1)
1.123 6.5454 9.54
(1)
1. 6. 9.
What is the expected correct behavior?
After b=a
assignment, I don't expect a
to be modified after b
was passed to plot2d(). Variable a
was converted to integer.