Hi Thomas, This is not correct:
In Mathematica, on the other hand, arguments are passed as values, meaning that the arguments are copied into the function’s local environment. This means that any modifications made to the arguments inside the function do not affect the original variables.
...associations are immutable data types, so we cannot modify them in-place anyways..
ClearAll[fChangeAssoc];
SetAttributes[fChangeAssoc, HoldFirst];
fChangeAssoc[assoc_, key_, newVal_] := AppendTo[assoc, key -> newVal];
assoc = <| "this" -> 1, "that" -> 2 |>
fChangeAssoc[assoc, "this", 3]
assoc
<| "that" -> 2, "this" -> 3 |>
Note that the first argument is NOT restricted as _Association when using the HoldFirst:
ClearAll[fChangeAssocWRONG];
SetAttributes[fChangeAssocWRONG, HoldFirst];
fChangeAssocWRONG[assoc_Association, key_, newVal_] := AppendTo[assoc, key -> newVal];
The following is not matched:
fChangeAssocWRONG[assoc]
fChangeAssocWRONG[assoc]