Hot answers tagged

41 votes
Accepted

What's the difference between Inactive and HoldForm?

Updated Both Hold and Inactive block evaluation; the key difference is that Inactive is ...
user avatar
  • 8,372
25 votes

Why is Unevaluated[#]& different from Unevaluated?

I thought that for any function f we could use "f" interchangeably with "f[#]&". That ...
user avatar
  • 225k
23 votes
Accepted

What are the cool kids talking about when they use ##&[]?

Try this: Map[If[#==1,Unevaluated@Sequence[],#]&,{1,2,3}] Note the output. The 1 is gone. That's because ...
user avatar
  • 25.1k
23 votes
Accepted

What's the difference between these 2 associations?

Preamble The real problem here seems somewhat deeper than what the (mostly correct) observations in comments indicate. In Mathematica, a number of objects, which are so-called raw objects (including ...
user avatar
21 votes
Accepted

Can't inject EncryptedObject

I think the problem might be related to a bug in FullForm when applied to a ByteArray object: ...
user avatar
  • 67k
19 votes

What's the difference between Inactive and HoldForm?

One difference is that NDSolve directly supports Inactive. It can be used to specify operators such as divergence ($\nabla\cdot$...
user avatar
  • 225k
18 votes
Accepted

Why is Unevaluated[#]& different from Unevaluated?

The two are not equivalent. Even if f lacks special attributes. Assuming no special attributes are present, a function's arguments are always evaluated before the ...
user avatar
  • 1,267
18 votes
Accepted

Why does Unevaluated applied (@@) to a held expression not work?

The action of the symbol Unevaluated is due to a special rule within the evaluator that occurs at a very specific time during the evaluation process. ...
user avatar
  • 67k
16 votes
Accepted

Pure functions are not functions?

A response to this comment: I understand that there are workarounds. I am wondering whether I am misinterpreting the manual. Yes. The use of the word "function" in the manual may be confusing ...
user avatar
  • 225k
16 votes
Accepted

How to uncompress strings safely (without any evaluation)?

This is definitely a bug. Here's a slightly simpler workaround than those suggested in the comments: Uncompress[str, HoldComplete] // InputForm Generally ...
user avatar
  • 13.4k
16 votes
Accepted

Easy printing of executable code

You could define a function similar to Echo with the difference that it won't evaluate its argument before printing. ...
user avatar
  • 225k
16 votes

Why is Unevaluated[#]& different from Unevaluated?

The head Unevaluated is a symbol with the HoldAllComplete attribute. The head ...
user avatar
  • 13.5k
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
14 votes
Accepted

What is the potential usage of ReplaceAllUnheld in Developer Utilities Package?

Thank you for bringing this function to my attention! It lets us use ReplaceAll without disturbing or even traversing held expressions. This is huge! I have ...
user avatar
  • 264k
14 votes
Accepted

HoldPattern vs Unevaluated

HoldPattern is a persistent head that prevents evaluation of its argument(s) yet is transparent to pattern matching. Unevaluated...
user avatar
  • 264k
13 votes
Accepted

Pattern does not match with Orderless head

I am betting that this is almost certainly an optimization short-cut. If Orderless had to try every ordering it would be extremely slow when there are a moderate ...
user avatar
  • 264k
13 votes
Accepted

Defer, Hold, Unevaluated, Inactivate -- which one when?

The SO duplicate Preventing evaluation of Mathematica expressions does a nice job of explaining the differences among and use-cases for Defer, ...
user avatar
  • 21.6k
12 votes

What's the difference between Inactive and HoldForm?

Although mfvonh's answer is a nice summary of Inactive formal properties, I think it misses several important points, which are both shown in the "Scope" and "...
user avatar
  • 2,661
12 votes
Accepted

How to properly inject iterators into table?

General I think that one can achieve the goal much easier if we reformulate the request. A variable is IMO not a proper object to store an iterator in the form of expression. What you really need is ...
user avatar
11 votes
Accepted

How to see a code preview (in Experimental`Explore[] or related GUI)

Quick fix is to use e.g. Inactivate and friends: ...
user avatar
  • 133k
11 votes
Accepted

Why one needs two Unevaluated to show 1+1 correctly in TreeForm?

This issue is known and it is a defect of TreeForm like Leonid already said. Let me give an illustrative example that shows the same behavior. Let us assume you ...
user avatar
  • 111k
11 votes
Accepted

Matching HoldPattern expressions

Clarification of HoldPattern usage: HoldPattern[expr] is equivalent to expr for pattern ...
user avatar
  • 133k
11 votes
Accepted

How to get a unevaluted expression from a compressed string?

You need to wrap the expression Unevaluated before passing it to Compress, which means defining your own function instead of ...
user avatar
  • 17.9k
11 votes
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 ...
user avatar
  • 133k
11 votes

Expanding a sum without evaluating it

may be Sum[With[{i=i},HoldForm[i^2]],{i,1,5}] But this uses a wrapper. I do not think there is a way without using Hold and ...
user avatar
  • 110k
11 votes
Accepted

Perform localized, evaluation-leak free replacements

Here's a way making use of Block to cause f to be inert: ...
user avatar
  • 45.5k
11 votes
Accepted

Getting terms and only evaluate specific parts of a series

times[{i_}] := i times[{i__}] := Inactive[Times][i] Sum[times@Table[2 i - 1, {i, n}]/times@Table[2 i, {i, n}], {n, 5}] If you prefer ...
user avatar
  • 52.7k
10 votes

What's the difference between Inactive and HoldForm?

I think the basic answer to your question is: 1) If you want absolute control over revaluation, nothing beats good old HoldComplete. It will be there to the end of time. 2) Inactive meant for much ...
user avatar
  • 13.4k
10 votes
Accepted

Held keys in associations

Wrap the entire key in Hold, if you really want to keep things that might evaluate in the keys of an association (HoldPattern is ...
user avatar
10 votes
Accepted

HoldForm does not Hold Form for fractions sometimes

Use HoldForm applied to each fraction to keep the fractions from combining. HoldForm[1/2] HoldForm[3/4] to produce $$ \frac{1}...
user avatar
  • 58.4k

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