Arguments are passed by value only (even with the "(var)" type cast). There is no intrinsic implementation in BEE for arguments passing by reference.
However, you can still pass arguments by reference by passing the variable name instead, and linking the variable to the parent context from inside the function. That way, changes made to the argument variable will survive the function exit because it is the linked parent variable that was changed..
In the following example, the variable name is in arg%x, and therefore the variable is indicated by {arg%x} and its element {arg%x}:key. (Also, the loop variable "foreach" is a copy of the loop source value, not the loop source element itself. To change the loop source, you need to explicitly assign a value to it.)
function addone {
if ({arg%x|isset} == 0 || {#arg%x:} == 0) return;
parent {arg%x};
foreach ({arg%x}) var {arg%x}:{foreach:key} conv=++;
var result%function = "(var){arg%x}";
}
var myArr = "(array)a=>1,b=>2,c=>3";
display "Before: {myArr|list}<br>\n"; // Output: Before: a=>'1',b=>'2',c=>'3'
addone x="myArr";
display "After: {myArr|list}<br>\n"; // Output: After: a=>'2',b=>'3',c=>'4'
display "Result is {result%addone|list}<br>\n";
(The string {arg%x}:{foreach:key} indicates the variable name. It evaluate to a variable name in the parent context (since we have parent {arg%x}). There is no need to quote a string in BEE unless it has white spaces in it. If you feel uncomfortable about the syntax, you can use var "{arg%x}:{foreach:key}" conv="++"; instead).
|