Questions about functions which maintain an expression in unevaluated form, including the use and behavior of Hold, HoldForm, HoldComplete, and HoldPattern. Also questions concerning the attributes HoldFirst, HoldRest, HoldAll, etc.

learn more… | top users | synonyms

58
votes
3answers
2k 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 ...
33
votes
3answers
2k views

Changing Values in an Association using Map

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as: ...
22
votes
3answers
431 views

Can't inject EncryptedObject

Bug present from 10.0 to 10.3.1 and fixed in 10.4.0 !! Here are minimal examples: ...
21
votes
2answers
799 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: ...
20
votes
5answers
2k 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 ...
19
votes
2answers
320 views

Pattern does not match with Orderless head

Why does the following pattern matching not succeed? ...
18
votes
1answer
223 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, ...
17
votes
2answers
473 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 ...
16
votes
4answers
448 views

Prevent graphics render inside 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 ...
15
votes
1answer
250 views

Why are the attributes of Plot changing?

In version 9, with a newly started Mathematica session, try the following code: ...
13
votes
4answers
358 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. ...
12
votes
7answers
626 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, ...
12
votes
2answers
787 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, ...
12
votes
1answer
202 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 ...
11
votes
3answers
235 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
518 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 ...
11
votes
2answers
323 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
282 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: ...
10
votes
2answers
275 views

Held keys in associations

Jacob Akkerboom commented: Note that PositionIndex does work correctly with held expressions, whereas this is a bit painful to implement using ...
9
votes
2answers
162 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
1answer
149 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
113 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 ...
9
votes
0answers
66 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 ...
8
votes
4answers
212 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 ...
8
votes
4answers
294 views

How to inject unevaluated list of Unique into a RuleDelayed?

I am writing a function that constructs a rule which has Unique[] in the RHS. Here is a simplified segment of code ...
8
votes
3answers
179 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 ...
8
votes
1answer
86 views

Matching HoldPattern expressions

My original problem is to delete all rules starts with a[1] from SubValues[a] For example, ...
7
votes
6answers
214 views

How to join held Lists?

Let's say I have a = Hold@{2+2} b = Hold@{4+4} How can I get Hold@{2+2,4+4} ie join the two held lists ? More ...
7
votes
2answers
269 views

HoldForm[Operator ##] on some list

Recently in response to this question Mr.Wizard suggested an unusual way to summing numbers. This doesn't seem to be documented. ...
7
votes
3answers
192 views

Converting StringJoin to StringForm inside Hold

Let's say I have a piece of code: Hold[{code1, "asdad " <> ToString[testa] <> " adsd " <> ToString[testb], code2}] (*MWE ofc*) ...
6
votes
4answers
333 views

Is there a more Mathematica-y way to label these plots?

I am studying an infinite square well in the context of quantum mechanics. ...
6
votes
2answers
95 views

Pattern matching an expression involving Times

I'm trying to write a Mathematica function that will format expressions according to my preferences, for example displaying (5 c x)/Sqrt[2] as ...
6
votes
1answer
75 views

How to force evaluation of an expression with Part left unnevaluated?

My goal is to minimize a real valued multi-variable function averageFreeEnergyDensity. The function accepts an integer argument ...
5
votes
4answers
332 views

Concatenating strings, unevaluated expressions and evaluated expressions/values

Maybe this is something very simple to some of you. Anyway, I think this can be useful to many others like me. I would like to build an output that involves strings, unevaluated expressions and ...
5
votes
5answers
268 views

Calculating N-th step of recurrent sequence

I am figuring out how to calculate $N$-th step of a square root approximation sequence: $$x_{n+1} = \frac12\left(x_{n} + \frac{a}{x_n}\right),$$ where $a$ is a number the root of which is to be found ...
5
votes
4answers
310 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} $$ ...
5
votes
3answers
255 views

Applying a function with the HoldAll attribute inside NestList

I'm trying to write an update function, which can be applied to a list and then to NestList it. As the function has to manipulate the given variable I figured I ...
5
votes
1answer
88 views

Why is NHoldFirst not propagated to symbolic derivatives?

I encountered a nasty problem that N cannot evaluate expressions containing a symbolic Derivative of a multi-parameter function ...
5
votes
0answers
120 views

Same input,different result? [duplicate]

Using this code,you can see,same input, but the output are different. So weird! If I copy this code here, it outputs normally. So what's the problem? Ps:I use ...
4
votes
3answers
156 views

Getting terms and only evaluate specific parts

I want to expand the expression but I do not want it to evaluate. Sum[(HoldForm[1/(2 # - 1) - 1/(2 # + 1)] &)[i], {i, 1, 6}] However if you evaluate this you ...
4
votes
2answers
186 views

Confusing ReplaceRepeated & Hold

I've been bootstrapping myself to the very alien world of Mathematica and there came my first WTF moment: ...
4
votes
4answers
1k views

Replace symbols with values without evaluation

If I have assigned values to a, b and c: ...
4
votes
2answers
217 views
4
votes
2answers
79 views

MatchQ failing in some cases with Hold [duplicate]

Could someone clarify why the first of these MatchQ finds a match whereas the second does not? (I'm using version 10.0, in case that matters.) ...
4
votes
1answer
64 views

HoldForm -> InputForm without processing the contents

I have programmatically generated a large number of simple equations like 1+1/2. I need them to be 'unprocessed', so they've been run through ...
3
votes
4answers
630 views

Make function return unevaluated equation

I have made this function which outputs the equation of a nth degree polynomial: ...
3
votes
3answers
111 views

Operations on expressions within Hold [duplicate]

I want to convert {Hold[1 + 2], Hold[3 + 4], Hold[5*6]} into Hold[{1 + 2, 3 + 4, 5*6}]. I have tried ...
3
votes
3answers
93 views

Can I hold a condition in NMaximize/NMinimize?

I'd like to use NMaximize/NMinimize with the condition ...