Skip to main content

Timeline for Error with AppendTo [duplicate]

Current License: CC BY-SA 3.0

8 events
when toggle format what by license comment
Feb 11, 2015 at 16:33 comment added Mr.Wizard Please see specifically: (18737)
Feb 11, 2015 at 16:33 history closed Mr.Wizard Duplicate of What are the most common pitfalls awaiting new users?
Feb 11, 2015 at 16:25 comment added Szabolcs ... attribute will allow it to evaluate to AppendTo[arr, 1] instead of AppendTo[{3,2},1].
Feb 11, 2015 at 16:23 comment added Szabolcs In that case start by reading through this up to and including "Nonstandard Evaluation" and understanding why AppendTo needs to have the HoldFirst attribute while Append doesn't. See also here. Then we can go from there. In short, f[x_]:=AppendTo[x,1]; arr={3,2}; f[arr] will evaluate as f[arr] -> AppendTo[{3,2}, 1], which causes an error. The HoldFirst ...
Feb 11, 2015 at 16:18 comment added kglr Add e2 = edges in the first argument inside Module (Module[{e2=edges, ...},...], and change edges to e2 in the rest (AppendTo[e2,...] and Graph[e2,...].
Feb 11, 2015 at 16:12 comment added Andrea Orta @Szabolcs: Yes, you understood correctly. I want to modify the list edges, adding the additional connections for my expanded graph.
Feb 11, 2015 at 16:03 comment added Szabolcs Are you trying to create a function that will modify its argument permanently? E.g. using a simpler example, after evaluating x={1,2}; addone[x], the value of x will have changed to, say, {1,2,1}. This is how AppendTo works. The more usual way of working in Mathematica is to leave x alone and return a modified list instead, just like Append does. Both solutions are possible though. Do I understand it right that you want to use the first one?
Feb 11, 2015 at 15:58 history asked Andrea Orta CC BY-SA 3.0