Bug - Not A Bug ASH: aggregate inside a function persists unexpectedly

Code:
void printoutput(int[int] input_argument)
{
    int[int] incremented = input_argument;
    print_html(incremented[1]);
    incremented[1] += 1;
}

int[int] input;
input[1] = 0;
printoutput(input);
printoutput(input);
printoutput(input);


Returns:

Unless I misunderstand something what is expected is
the aggregate inside the function would not keep a persistent value when the function is called several times,
the input would prevail when writing it into the aggregate,
or an error message if it's wrong to modify a copy of an aggregate that was passed as argument? there is no error like "Cannot modify constant value"
 

Veracity

Developer
Staff member
Aggregates are passed by reference. We do not make a deep copy that you can modify without affecting other places that have that reference.

Just like Java.

I have written many scripts that depend on this behaviour.

This is behaving as intended.
 
Ok thanks for clarifying
the aggregate inside the function was not persisting, instead the "input" aggregate itself was getting modified
 

Veracity

Developer
Staff member
Right. ASH passes objects around. Objects like ints, floats, strings, elements, … are not mutable. Composite objects - maps, arrays, records - are mutable. There are some aggregate objects -plural typed constants - $ints[1, 2, 3], for example - which are immutable. But aggregates you create by yourself can be passed to a function and modified there and the caller will see the modifications.
 
Top