[Scilab-users] Scilab 6 - Problem with scope and nested lists

Arvid Rosén arvid at softube.com
Fri Oct 16 13:35:13 CEST 2020


Hi!

We have found a tricky issue when moving over from Scilab 5 to Scilab 6 in my organization. We have a lot of code which works with nested lists, and functions modifying those lists. However, when a function is called with some nested lists as an input argument, the body of that function can change the value of the variable in the calling scope. This was not the case in Scilab 5, and the issue is super tricky to hunt down in our quite extensive code base. Below is a short example of the problem, and how to reproduce it.

I have also filed a bug report here: https://bugzilla.scilab.org/show_bug.cgi?id=16556

Is anyone else seeing this problem? And do you have any workarounds or other suggestions?

Cheers,
Arvid

------

// Define variables
testArray = list();
for i=1:1:10
    testArray($+1) = list();
    for j=1:1:10
        testArray(i)($+1) = [];
        testArray(i)(j).testMember = 1;
    end
end
testArrayOrig = testArray;

// Define functions
function outArray = testFunc(inArray)
    for i=1:1:10
        for j=1:1:10
            inArray(i)(j).testMember = 5
        end
    end
    outArray = inArray;
endfunction

// Send the variable as argument to the function
if %t
    testArrayOut = testFunc2(testArray);

    if testArrayOut(1)(1).testMember == testArray(1)(1).testMember
        error("Error! inputArgument was changed by function");
    end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20201016/bb9acf91/attachment.htm>


More information about the users mailing list