The following code works
ccc = {};
AppendTo[ccc, 5];
ccc
and gives the output {5}
However, the following code does not work:
ccc={};
cc[emptySet_] := AppendTo[emptySet, 5]
cc[ccc]
Instead giving the error "AppendTo: {} is not a variable with a value, so its value cannot be changed."
Why does the second way not work?
- From the error I'm guessing the definition of
ccc
is being substituted for forccc
, which is not a variable. - I imagine this is probably me just defining the function incorrectly, with some trivial error (maybe I need a hold or a condition something)
cc[emptySet_] := Append[emptySet, 5]
and notAppendTo
. $\endgroup$cc[Unevaluated@ccc]
$\endgroup$