59 votes
Accepted

Changing Values in an Association using Map

Preamble This is a very good question, because answering it will make it very clear what immutability means, both in general and in the context of Associations. ...
user avatar
57 votes
Accepted

Scan vs. Map vs. Apply

These three functions are similar (speaking commonly), and in some applications any of them could be used, yet they have very different special applications. Rudimentarily: ...
user avatar
  • 264k
32 votes

Changing Values in an Association using Map

I hesitate to add anything after @Leonid's comprehensive answer, but I'd like to point out that an easy way to achieve the stated goal is to define f like this: <...
user avatar
  • 67k
28 votes
Accepted

Make my data-structure atomic

Yes. Use System`Private`SetNoEntry on any expression which you want to protect in this manner. This works on per-expression basis, so you have to apply this ...
27 votes
Accepted

How to completely delete the head of a function expression

You can actually Delete the head of the expression, which is part 0: ...
user avatar
  • 264k
25 votes
Accepted

How to extract parts from atomic expressions like DelaunayMesh and Graph?

I'm going to take this as a general question, referring to all atomic objects, not just DelaunayMesh. By design, atomic objects like ...
user avatar
  • 224k
24 votes

Can we intelligently control evaluation in Thread?

Analysis of the problem All functions in Mathematica either hold one or more of their arguments, or per The Standard Evaluation Procedure the arguments are evaluated before the function is applied. <...
user avatar
  • 264k
24 votes

Cleanest way to take a[b[c]] to a[b][c]

test = a[b[c[d]]]; Fold[ Construct, (* or Compose, see [1] *) Level[test, {-1}, Heads -> True] ] a[b][c][d] [1] - ...
user avatar
  • 132k
21 votes
Accepted

Shorthand for map at level 2

Corrected to use SubscriptBox as Rojo showed and Kvothe commented, fixing binding. Rojo shows a way in Is it possible to define custom compound assignment ...
user avatar
  • 264k
20 votes
Accepted

ToExpression processing errors

One way would be to redirect all messages issued by ToExpression to a string-stream. Here is an example of that approach, with minimal error-checking: ...
user avatar
  • 67k
20 votes
Accepted

Custom atomic expressions - modern tutorial

I have a new package for speeding up the construction of things like these which I discuss at the end Atomic vs Valid These are two related but distinct concepts. The former indicates that we can't ...
user avatar
  • 45.4k
19 votes

How to extract parts from atomic expressions like DelaunayMesh and Graph?

I think this is the simplest fast way to convert an atomic expression to an equivalent compound form, to be able to inspect and manipulate its "apparent" full form: ...
19 votes
Accepted

How can I obtain a complete list of the kinds of atomic expressions in the Wolfram Language using only the language itself?

You can use EntityValue to find out what symbols can be atomic: ...
user avatar
  • 123k
18 votes

Extracting variables from an expression

Using an undocumented function: ...
user avatar
18 votes

How to extract parts from atomic expressions like DelaunayMesh and Graph?

Motivation Recently, I wanted to extract parts of an atomic expression, and my first thought was to use a ToExpression/ToString ...
user avatar
  • 123k
18 votes
Accepted

When is the righthand side of a RuleDelayed evaluated?

There seems to be a subtlety in the way delayed rules are used. Have a look at the following: ...
user avatar
  • 9,859
18 votes

Can we intelligently control evaluation in Thread?

First, let me tell you that my answer here is by no means a replacement for the trickier, but more capable implementation of Mr. Wizard. What I want to show is that the examples I point out at the end ...
user avatar
  • 111k
17 votes
Accepted

How to do algebra on summations of variable expressions?

As far as I know, there is no easy, general way to handle this kind of algebra with Sum expressions. What follows is an attempt to use replacement rules to handle ...
user avatar
  • 83.3k
17 votes
Accepted

Import package with correct symbol contexts

...
user avatar
  • 132k
16 votes

How to change plot style or other options after it was created

As Mr.Wizard indicated, you can also reconstruct the plot using the data. Here is an example: ...
user avatar
16 votes

How to replace the first Head of a currying expression like "a" in a[b,c][d]?

y = a[b, c][d]; y[[0, 0]] = w; y (* w[b, c][d] *)
user avatar
16 votes
Accepted

Evaluated vs. unevaluated Association

Summary The confusion we observe here is largely due to ambiguous use of the symbol Association as an expression head. On the one hand, ...
user avatar
  • 67k
15 votes

Scan vs. Map vs. Apply

For a visual, animated, description of basic behavior of such functions, I recommend: http://reference.wolfram.com/legacy/flash/ (You may want to turn on your computer's sound.)
user avatar
  • 11.3k
15 votes
Accepted

List of atomic expressions

You can executive the code in mma 10 or above version EntityClass["WolframLanguageSymbol", "Atomic"]//EntityList But is not all atomic function,as I know.
user avatar
  • 23.1k
15 votes
Accepted

Is there a way to control which special forms Normal converts?

Yes. It turns out that Normal accepts an undocumented second parameter which may be a Symbol or a list of Symbols and it will only affect those forms. Plain ...
user avatar
  • 264k
15 votes
Accepted

Joining two lists with relational operators

Thread[liste - listv <= 0] // Reduce 2 <= y <= 3 && z >= 4 && x <= 1 ...
user avatar
  • 132k
14 votes
Accepted

First order approximation

You can use Series to specify the order of approximation. When an expression involving the output of Series, which is a ...
user avatar
  • 213k
14 votes
Accepted

Is there a built-in function to inverse Thread?

Let's make this a little more challenging: ...
user avatar
  • 264k
14 votes
Accepted

How to replace $x$ and $x^2$ with different value?

Give the replacement rules in a list: expr /. {x^2 -> k p + k (k - 1) p^2, x -> k p} 2 k p + (-1 + k) k p^2
user avatar
  • 349k
14 votes
Accepted

Conflict with hidden names

First, you should never give Plus a downvalue. Always give your symbol upvalues instead by using TagSetDelayed. Giving such a ...
user avatar
  • 123k

Only top scored, non community-wiki answers of a minimum length are eligible