I have two questions that I think go hand in hand.
I am trying to reuse the same local (!) variable name (res) in two different functions. In both cases, res is an undeclared array that stores the return value of its respective function. To my surprise, calling function1 and then function2 will overwrite the results of function1 - now, both functions point to res of function2:
function1(myList):=
block(
[res],
for i in myList do
res[i]: i+2,
res
)
;
function2(myList):=
block(
[res],
for i in myList do
res[i]: i+4,
res
)
;
aList: [0, 1, 2, 3];
[0, 1, 2, 3]
output1: function1(aList);
res
output2: function2(aList);
res;
listarray(output1);
[4, 5, 6, 7]
listarray(output2);
[4, 5, 6, 7]
My questions would be:
- Why is
resnot the local variable I expect it to be? - Is there an alternative to using
listarray? I know that I could have used it directly in the return statement of each function but the admins of the system I am working on have blacklistedlistarrayfor some reason.