is an attribute that specifies that all arguments to a function are to be maintained in an unevaluated form.
HoldAll
is an attribute that specifies that all arguments to a function are to be maintained in an unevaluated form.
Details
- You can use Evaluate to evaluate the arguments of a HoldAll function in a controlled way. »
- Even when a function has attribute HoldAll, Sequence objects that appear in its arguments are still by default flattened, Unevaluated wrappers are stripped, and upvalues associated with the arguments are used. »
Examples
open all close allBasic Examples (1)
Give the function f the attribute HoldAll:
SetAttributes[f, HoldAll]As a result, arguments are not evaluated prior to entering the (in this case nonexistent) function body:
f[1 + 1, 2 + 2, 3 + 3]Compare with a function g that has no attributes:
g[1 + 1, 2 + 2, 3 + 3]Scope (2)
This is the full form of the evaluation result:
FullForm[1 - 1]This is the full form of the input, before evaluation:
HoldForm[FullForm[1 - 1]]This is made possible by the fact that HoldForm has the HoldAll attribute:
Attributes[HoldForm]Give the function inout the attribute HoldAll:
SetAttributes[inout, HoldAll]Define a function of two arguments that returns them wrapped in Hold as well as the first without wrapping:
inout[in_, tag_] := {Hold[in], in, Hold[tag]}Neither argument is evaluated prior to entering the function body, but the first argument is evaluated inside the function:
inout[1 - 1, 1 + 1]Applications (3)
Many functions with scoping behavior have the HoldAll attribute:
Attributes[Plot//Evaluate]Plotting lists of functions will use separate styling for the different functions:
Plot[{Sin[x], Cos[x]}, {x, 0, 2π}]If the list structure is not manifest, no separate styling is provided:
Plot[Through[{Sin, Cos}[x]], {x, 0, 2π}]Use Evaluate to make the list structure manifest:
Plot[Evaluate[Through[{Sin, Cos}[x]]], {x, 0, 2π}]Different vector-valued functions in a list will still get separate styling:
Plot[{Through[{Sin, Cos}[x]], Through[{Tan, Cot}[x]]}, {x, 0, 2π}]Use HoldAll and Unevaluated to suppress evaluation of symbols wherever it would occur:
SetAttributes[symbolLength, HoldAll];
symbolLength[s_Symbol] := StringLength[SymbolName[Unevaluated[s]]]Find the length of a symbol's name even if it has a value:
xyzzy = 1;symbolLength[xyzzy]Implement your own control structure:
until::usage = "until[cond,cmd] repeats evaluating cmd until cond is True.";SetAttributes[until, HoldAll]until[cond_, cmd_] := While[True, cmd;If[cond, Return[]]]i = 1;
until[Prime[i] > 10 ^ 6, i++];iProperties & Relations (12)
Hold is a container with the attribute HoldAll:
Attributes[Hold]Hold[1 + 2]Functions that operate on symbols often need the HoldAll attribute:
i = 5;
Protect[i]Without the attribute, they would operate on the symbol's value:
Protect[Evaluate[i]]Control structures such as Table protect their arguments from evaluation:
i = 5;Table[i, {i, 1, 4}]Otherwise, global values might interfere with their operation:
Table[Evaluate[i], {i, 1, 4}]Use Evaluate to force evaluation of an argument of a HoldAll function:
Attributes[Unprotect]syms = {Plus, Times};Unprotect[Evaluate[syms]]Force evaluation of the right-hand side of a delayed definition:
Expand[(1 + x) ^ 3]f[x_] := Evaluate[%]Definition[f]Use Unevaluated to temporarily treat a function as if it had the attribute HoldAll:
Length[Unevaluated[1 + 2 + 3]]Length[1 + 2 + 3]Suppress the evaluation of the arguments of a pure function:
Function[e, Hold[e], {HoldAll}][1 + 2]Function[e, Hold[e]][1 + 2]Sequence splicing still happens for functions with the attribute HoldAll:
SetAttributes[f, HoldAll]
f[Sequence[a, b, c]]Unevaluated is stripped prior to entering the function body:
f[x_] := Hold[x]
f[Unevaluated[1 + 1]]_[___, g, ___] ^:= "upvalue"
f[Sequence[a, b, c], g]The attribute HoldAllComplete suppresses all three behaviors:
Attributes[HoldComplete]HoldComplete[Sequence[a, b, c], g]Substitution works inside a held expression:
Hold[f[1 + 2]] /. f[x_] :> g[x]Insert into a held expression:
Insert[Hold[x + x], y, {1, 2}]NHoldAll protects arguments from N but evaluates them normally otherwise:
Attributes[Derivative]N[Derivative[1 + 1]]N[f[1 + 1]]HoldPattern protects patterns from evaluation but does not interfere with pattern matching:
{HoldPattern[_ + _], _ + _}See Also
Unevaluated Hold HoldFirst HoldRest SubValuesHoldAll NHoldAll HoldAllComplete SequenceHold HoldForm Inactivate Extract
Function Repository: HoldArguments
Tech Notes
Related Guides
Related Workflows
- Substitute Values of Variables in Functions That Hold Their Arguments
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), HoldAll, Wolfram Language function, https://reference.wolfram.com/language/ref/HoldAll.html.
CMS
Wolfram Language. 1988. "HoldAll." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/HoldAll.html.
APA
Wolfram Language. (1988). HoldAll. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HoldAll.html
BibTeX
@misc{reference.wolfram_2026_holdall, author="Wolfram Research", title="{HoldAll}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/HoldAll.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_holdall, organization={Wolfram Research}, title={HoldAll}, year={1988}, url={https://reference.wolfram.com/language/ref/HoldAll.html}, note=[Accessed: 13-June-2026]}