# Tag Info

## Hot answers tagged assignment

### How to pass variables by reference and by value

You asked for a general explanation instead of just focusing on specific application examples, so here it goes ... The concepts of "pass by reference" and "pass by value" that you ...
• 236k

### How do you set attributes on SubValues?

This is an old discussion but is about an issue that resurfaces every now and then. One of the best (for a given sense of elegance) answers is the one posted on Stack Overflow ...
• 2,105
Accepted

### Duplicate the swap function

Attributes[swap] = HoldAll; swap[x_, y_] := {x, y} = {y, x}; x = 1; y = 2; swap[x, y]; {x, y} {2, 1} There are two ...
• 272k

### Part not behaving the way I expect it to

The way Set works in setting parts of an expression is this: symb[[..<part specification>..]] = values; The component <...
• 239k
Accepted

### How would you explain Nothing[] weirdness?

I think the best way to understand this behavior is with this example, ...
• 69.2k

### Problem with function inside brackets. Bug?

No, not a bug. Let's think about how AppendTo may be implemented (even though the actual implementation isn't inspectable). ...
• 236k
Accepted

### Confusion about HoldFirst attribute of Set

The problem is not related to Set in general but to how Set works with Part on a left hand ...
• 137k

### Can't understand one paragraph in Power Programming with Mathematica

He is simply saying that the first argument of Set is not evaluated before Set creates the definition. However, the sub-parts ...
• 236k
Accepted

### Problem with function inside brackets. Bug?

Here's the issue. In the second (non-working) code, RandomInteger[{1, Length[a]}] is evaluated twice, as we can see by Trace...
• 24k

### Confusion about HoldFirst attribute of Set

Kuba's answer explains why the first form does not work, but it does not address why the second form does work. That has been discussed in other questions DownValue assignment using Apply Why is the ...
• 272k
Accepted

### Error Message when nothing should be evaluated

This is due to the special behavior of SetDelayed (:=) with regards to the first argument (see e.g. this question): The ...
• 34.2k

### What is the difference between Set and SetDelayed?

Another quick example: I have a function: f[x1_,x2_]:= x1+x1*x2 and I want to find it's derivative according to x2 at specific locations of x1 and x2. ...
• 2,510
Accepted

### Apply ToString to a list of variables

In addition to Mr.Wizard's answer here is a collection of other possibilities: ...
Accepted

### What is the point of tagset /:?

TagSet is useful for assigning UpValues to symbols. These are often used to make built-in functions do something different for ...
• 24k
Accepted

### Why Optional in Set is not held by the HoldFirst attribute?

From the "Details" of the docs for HoldPattern The left-hand sides of rules are usually evaluated, as are parts of the left-hand sides of assignments. You can ...
• 239k
Accepted

### How can I list the common elements of two lists?

If you need the duplicate 9 in the output: ...
• 176

### Assign the results from a Solve to variable(s)

Here's a painless solution: s = Solve[y^2 == 13 x + 17 && y == 193 x + 29, {x, y}]; Assign the four results of the solution s above to a variable each, ...
• 964

### How can I assign many values each to a different variable?

First of all, please note that coding this way in Mathematica is asking for trouble. Use of (lots of) mutable variables is strongly discouraged. The following will show you why: Clearing all symbols <...
• 8,499

### How to pass variables by reference and by value

You need: SetAttributes[myfunc, HoldAll] You then have: ...
• 40.1k

### assignments within Manipulate

Updated to handle \$ showing from using module variable. Add TrackedSymbols :> {c} and add ...
• 147k

### Transferring DownValues

You can make use of the undocumented LanguageExtendedDefinition function that underlies the Wolfram Cloud. Suppose: ...
• 131k
Accepted

### Assigning values to association in DownValues

This is nothing unique to Association; the same issue affects simple lists: a[1] = {1, 2, 3}; a[1][[2]] = 7; Set::setps: a[...
• 272k

### Duplicate the swap function

Just a reminder for advanced users, to show the complexity of the problem : keywords : David Wagner power programming swap byname
• 18.7k

### Can't understand one paragraph in Power Programming with Mathematica

If Set would not have the HoldFirst attribute, it would lead to undesired behavior if variables on the left hand side have ...
Accepted

### Transferring DownValues

DownValues[cc] = DownValues[cctemp] /. cctemp -> cc; cc @@@ {{1, 2}, {2, 6}, {3, 7}, {1, 9}} {13, 8, 4, 87} If cc has ...
• 399k

### What is the point of tagset /:?

As an addendum to Sjoerd's great answer, I would simply like to show a use case for defining a custom data type and then using TagSet to create what is called an ...
• 13.5k

### Why the difference in performance? Array vs List and Delete vs Nothing`

data2[[3]] = x; // AbsoluteTiming might give a hint. I explain it to myself as follows: At that point when you execute ...
Accepted

### Cannot assign variable value inside Do Loop

Mathematica is a term rewriting system. It will replace x1, x2, x3 by their values as soon ...
• 872
Accepted

### Defining a function iteratively without Mathematica getting stuck in a recursion loop

You can define the function(s) recursively: ...
• 69.4k