Linked Questions
39 questions linked to/from How to modify function argument?
13 votes
2 answers
6k views
How to pass variables by reference and by value [duplicate]
I haven't seen this question specifically addressed before in this site, although some hints and traces have been given, for instance, here: Pass by reference for an option argument Does pass-by-value ...
11 votes
1 answer
2k views
Modifying a List in a function in place [duplicate]
An example will be most specific: func[list_, column_] := list[[All, column]] = Map[#*2 &, list[[All, column]]]; This throws errors. I want to avoid doing ...
0 votes
1 answer
2k views
How can I change variable passed to a function? [duplicate]
Sometimes I'd like to make a function, which would take an argument "by reference" instead of usual "by value". This is semantically similar to what e.g. AppendTo ...
3 votes
1 answer
2k views
How to pass multiple results calculated in a module to global variables? [duplicate]
For example, I defined a user function with a module and what this function does is take the values of two global variables ga and ...
1 vote
1 answer
1k views
Change input variable in a function [duplicate]
I'd like to write a function, that would take a matrix as an input parameter and would change it by multiplying one of its rows by a factor. I try to do it in the following way: ...
2 votes
2 answers
245 views
How to set a values inside a custom function [duplicate]
I have a custom function like this stringLength[string_] := StringLength[ ToExpression[StringJoin[ToString /@ {del, string}]] = StringDelete[string, " "]] ...
0 votes
1 answer
431 views
Part assignment is not a symbol [duplicate]
read some related posts and found no solution. For a list defined like this m = {0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.0, 1.5, 1.6}; when I define this function ...
1 vote
1 answer
145 views
How to define a function having many steps? [duplicate]
I can't transform a simple code into a function. The function should take an integer and return a list of digits in a factorial number system: ...
1 vote
1 answer
159 views
Circumventing the default scoping: Assign a variable inside a function [duplicate]
I'm currently trying very hard to assign a variable inside a function. Therefore I'm using a function like this, which should reassign a predefined variable. ...
0 votes
1 answer
135 views
Symbol in Global Context but List in Module and Block? [duplicate]
Can someone explain the principles underlying the following behavior. I define the list testD, and then use a Do loop to change values in the list (I realize there are smarter ways but they don't fit ...
0 votes
0 answers
138 views
Calling Clear within a function [duplicate]
I want to create a function that when it is called clears the value of a parameter. For example I want to keep the value of a parameter and then clear its valueby calling a function: ...
2 votes
0 answers
103 views
How to modify a global large array in a function [duplicate]
Assuming variable x is a long list, which needs 1GB memory to store. I want to modify x in a function, such as let x[[10]]=1, using ...
0 votes
0 answers
26 views
How to assign values to a matrix by passing it to function? [duplicate]
I have written a function to assign values to a matrix putConj[arr_, i_, j_, val_] := Block[{}, arr[[i, j]] = val; arr[[j, i]] = val\[Conjugate]; ] This ...
559 votes
37 answers
139k views
What are the most common pitfalls awaiting new users?
As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
25 votes
5 answers
6k views
How to pass a symbol name to a function with any of the Hold attributes?
Given a function with the attribute HoldFirst, HoldAll or similar, and a variable, list, how ...