Questions tagged [hold]

Questions about functions which maintain an expression in unevaluated form, including the use and behavior of Unevaluated, Hold~ functions, Inactive related functions or Hold~ attributes.

Filter by
Sorted by
Tagged with
91
votes
4answers
4k views

Replacement inside held expression

I wish to make a replacement inside a held expression: f[x_Real] := x^2; Hold[{2., 3.}] /. n_Real :> f[n] The desired output is ...
67
votes
10answers
3k views

Injecting a sequence of expressions into a held expression

Consider the following toy example: Hold[{1, 2, x}] /. x -> Sequence[3, 4] It will give Hold[{1, 2, Sequence[3, 4]}] ...
46
votes
4answers
1k views

What's the difference between Inactive and HoldForm?

In version 10, Mathematica not only added Inactive / Activate but also highlighted this change in the "New in 10" page (in Core ...
31
votes
2answers
2k views

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

All the cool kids are apparently using ##&[] for Unevaluated @ Sequence[] but I have no idea what either means. ...
29
votes
3answers
934 views

Why is Unevaluated[#]& different from Unevaluated?

...
26
votes
1answer
739 views

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

What are some guidelines on which function to select from among the superficially similar functions Defer, Hold, ...
25
votes
5answers
5k 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 ...
22
votes
2answers
1k views

How to inject an evaluated expression into a held expression? [duplicate]

I know that there are methods to structurally manipulate held expressions (discussed e.g. here), but I failed to apply those for this particular problem: ...
22
votes
3answers
506 views

Can't inject EncryptedObject

Bug present from 10.0 to 10.3.1 and fixed in 10.4.0 !! Here are minimal examples: ...
22
votes
2answers
443 views

Pattern does not match with Orderless head

Why does the following pattern matching not succeed? ...
21
votes
1answer
260 views

How to uncompress strings safely (without any evaluation)?

Compressed strings are often used to exchange Mathematica expressions on the Internet. It is, however, not easy to see what such expression will do after decompression. Resulting code can perform ...
20
votes
2answers
743 views

When should I, and when should I not, set the HoldAll attribute on a function I define?

I have seen a number of examples on this site (such as in syntax highlighting and checking evaluation status) in which functions definitions are preceded with ...
19
votes
5answers
642 views

Prevent graphics from rendering inside a held expression

Assuming each odd line is input I would like the even lines to be the output of the following lines. In the above the Graphics are inside ...
18
votes
1answer
391 views

Why are the attributes of Plot changing?

In version 9, with a newly started Mathematica session, try the following code: ...
17
votes
4answers
546 views

Replacing parts of a held expression with held parts of another expression

I'm applying the Trott-Strzebonski technique in order to replace inside a held expression. ...
17
votes
1answer
1k views

Get the name of a symbol passed to a function

I'm trying to get the name of a symbol passed to a function with this: f[x_] := {SymbolName[x], x} SetAttributes[f, HoldFirst] x = 5; f[x] But ...
16
votes
3answers
321 views

Why is the first argument of the SetDelayed evaluated?

In[1]: f=g; In[2]: SetDelayed[f[x_],x^2]; In[3]: ?f Global`f f=g In[4]: ?g Global`g g[x_]:=x^2 However, SetDelayed has the ...
16
votes
1answer
125 views

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

There is a function ReplaceAllUnheld metioned in the doc Developer/ref/ReplaceAllUnheld. I am curious about what is the ...
14
votes
7answers
798 views

How to properly inject iterators into table? [duplicate]

Goofing off on a prior question, I was fiddling with other methods, which led me to the need to inject a constructed set of iterators into a table construct. Now, ...
14
votes
3answers
293 views

Evaluated vs. unevaluated Association

This question might have a remote connection to my older question, it is also about sameness of expressions and subtle differences observable only in certain forms. I encountered this strange ...
13
votes
2answers
1k views

Displaying a series obtained by evaluating a Taylor series

Description of problem I would like to use Mathematica to display the series obtained by substituting a value for $x$ in a Taylor series expansion. The terms of the series will be rational numbers, ...
13
votes
3answers
524 views

Unexpected behavior of Unevaluated

This question of mine got a bit ruined by the fact that I got a bit confused. I hope this separate question will take away this confusion. My confusion was that I found it strange that we have, for <...
13
votes
2answers
280 views

Matching HoldPattern expressions

My original problem is to delete all rules starts with a[1] from SubValues[a] For example, ...
13
votes
1answer
334 views

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

I have been messing around with built in Experimental`Explore[] function. You can call the function in Mathematica yourself to see what it looks like. It is a GUI ...
13
votes
1answer
118 views

Report: IgnoringInactive: a bug?

Bug introduced in 10.0.0 and fixed in 10.0.1 Just to report. IgnoringInactiveshould work with Cases. In agreement with the ...
12
votes
1answer
412 views

Easy printing of executable code

I'm working on a package that has functions that call other existing and packaged functions. I'd like a way to output what some of those key calls are, so users can see what's happening under the ...
11
votes
3answers
283 views

Creating a custom context with a Hold construct

I'm trying to create a function "InContext" to execute a piece of code inside a certain context (and to return the result of evaluating that piece of code). One approach is to place the code inside a ...
11
votes
1answer
193 views

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

I do not understand why Unevaluated sometimes does not work. Consider this expression: expr = Hold[a - a] Now let's say I ...
11
votes
2answers
410 views

Held keys in associations

Bug introduced in 10.0 and persisting through 11.0.1 or later Bug introduced in 10.0 and fixed in 10.4 Association is new in 10.0. Bug still present: ...
11
votes
2answers
419 views

How can you stop ordering of InputField entries?

I have: InputField[Dynamic[d]] Dynamic[d] If I enter e.g. a b x^5 h m the entry automatically gets sorted, as per screen ...
11
votes
1answer
390 views

Why does Plot[Hold[x], {x,0,1}] work?

It appears that, counter to my expectation, all of these (and probably many others) seem to work fine: ...
11
votes
1answer
157 views

TextString evaluation leak

Bug introduced in 10.4 or earlier and persisting through 11.3 [...] I checked and reproduced your issue, and have passed along a report to our developers on the same [...] CASE:3972929 ...
11
votes
1answer
196 views

KeyValuePattern in matching and replacement in nested associations

This case revealed I am missing something in pattern matching and evaluation in case of match, or I can't grasp it due to the busy week I have. Either way, I find this problem interesting for wider ...
10
votes
3answers
181 views

Perform localized, evaluation-leak free replacements

Consider the following expression: expr = Hold[ { f[ {1, {Print@1}} ], g[ {{{Print@1}}} ] } ]; I'm looking for a way to ...
10
votes
1answer
200 views

HoldPattern vs Unevaluated

For learning purposes I created this code: {g, 3*(10 + g)} /. HoldPattern[Plus[t__]] :> (Plus[t] /. g -> h) I am learning about HoldPattern. As I ...
10
votes
1answer
173 views

How to get a unevaluted expression from a compressed string?

Of course we know Defer[Range[20]] Range[20] But I try to compress my expression into a string ...
10
votes
2answers
215 views

How to explain the behaviour of TreeForm? [duplicate]

Just try this: g=1;a=1;TreeForm[Hold[g[a]]] The weird thing in the outcome is that the node of g displays 1 ,and a is still a. I do not know how to explain ...
10
votes
1answer
193 views

Problems with Dataset's querying on a fresh Kernel

Bug introduced in V10.4.1 or earlier and fixed in V11.3 A support case with the identification [CASE:3710757] [...] I checked and reproduced the issue at my end and have reported the issue to ...
10
votes
1answer
173 views

Is there a way to TagSet a HoldAllComplete function?

Let's say I want to overload the built-in function Lookup, to handle my data wrapped in myObject. One would use ...
9
votes
3answers
299 views

Expand series unevaluated

I'm newbie in Mathematica. I'd like to obtain nice and verbose output for any series calculation. For example, given a simple sequence n*(-1)^(n-1) and ...
9
votes
2answers
204 views

Confusion about HoldFirst attribute of Set

Set has the attribute HoldFirst. Expectedly the following does not work, i.e. it does not assign the OwnValue of 3 to x: ...
9
votes
4answers
753 views

HoldForm does not Hold Form for fractions sometimes

I'm facing a strange behavior of HoldForm. I need to display 1/2*3/4 in LaTeX like this : $$ \frac{1}{2} \times \frac{3}{4} $$ ...
9
votes
2answers
299 views

Passing an unevaluated part of an association to a function

I'm making a UI widget that controls sound volume on a speaker using a slider, e.g.: ...
9
votes
2answers
370 views

How do I restore HoldAll, HoldFirst, HoldRest attributes of Inactivated functions

Let f be defined as follows: ClearAll[f]; SetAttributes[f, HoldFirst]; f[1+1] (* f[1+1] *) The ...
9
votes
1answer
192 views

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

The task sounds simple, give the tree plot of 1+1. However, after some trying, I can only make this possible by using two Unevaluated. ...
9
votes
1answer
226 views

How do I insert OwnValues inside a held expression without evaluating it?

Here is a very long and complicated expression, which we abbreviate as a. I store it using SetDelayed because I want to perform ...
9
votes
3answers
261 views

HoldForm: Display exactly as entered?

Sometimes, Mathematica's internal representation of expressions can give somewhat surprising results. Specifically, I noticed this when I tried to preserve products of fractions for display. E.g. ...
9
votes
1answer
190 views

Why there is only `HoldFirst` but no `HoldSecond`, `HoldThird`, …`HoldN`?

I feel that this must be a duplicate. But I just can't find such a post. Mathematica has HoldFirst, HoldRest, ...
9
votes
1answer
152 views

FullSimplify Produces Result that Includes Hold

Bug fixed in 10.2.0 In the course of developing a solution to Question 79183, I solved the equation ...
8
votes
4answers
277 views

Hold expression with RandomInteger

One more question for today: I'm trying to show two random integers with a plus (+) sign between them, in an unevaluated form. I know how Hold and HoldForm work, but they hold everything, including ...

1 2 3 4 5 6