is an attribute that specifies that the first argument to a function is to be maintained in an unevaluated form.
HoldFirst
is an attribute that specifies that the first argument to a function is to be maintained in an unevaluated form.
Examples
open all close allBasic Examples (1)
Give the function f the attribute HoldAll:
SetAttributes[f, HoldFirst]As a result, the first argument is 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)
SetAttributes does not evaluate the symbols in its first argument:
f = c;
SetAttributes[f, Constant]As a result, the preceding input set the attribute on f, not c:
Attributes[{f, c}]This is made possible by the fact that SetAttributes has the attribute HoldFirst:
Attributes[SetAttributes]Give the function inout the attribute HoldFirst:
SetAttributes[inout, HoldFirst]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]}The second argument is evaluated prior to entering the function body, while the first is evaluated inside the function body:
inout[1 - 1, 1 + 1]Applications (1)
Definitions for unevaluated expressions can implement call-by-name semantics:
SetAttributes[f, HoldFirst]f[sym_, val_] := (sym = val ^ 2)x = 17;f[x, 5]The global variable has been modified:
xProperties & Relations (6)
Functions that operate on symbols often need the HoldFirst attribute:
Attributes[SetAttributes]i = 5;
SetAttributes[i, Constant]Assignments do not evaluate their left-hand sides:
Attributes[Set]i = 5;i = 6;Use Evaluate to force evaluation of an argument of a HoldFirst function:
SetAttributes[h, HoldFirst]h[Evaluate[1 + 1], 2 + 2, 3 + 3]Suppress the evaluation of the first argument of a pure function:
Function[{e, f}, Hold[e, f], {HoldFirst}][1 + 2, 2 + 3]Sequence splitting still happens for HoldFirst functions:
SetAttributes[f, HoldFirst]f[Sequence[1 + 1, 2 + 2], 3 + 3]NHoldFirst protects arguments from N but evaluates them normally otherwise:
Attributes[EllipticTheta]N[EllipticTheta[1, a, b]]EllipticTheta[1 + 1, a, b]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), HoldFirst, Wolfram Language function, https://reference.wolfram.com/language/ref/HoldFirst.html.
CMS
Wolfram Language. 1988. "HoldFirst." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/HoldFirst.html.
APA
Wolfram Language. (1988). HoldFirst. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HoldFirst.html
BibTeX
@misc{reference.wolfram_2026_holdfirst, author="Wolfram Research", title="{HoldFirst}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/HoldFirst.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_holdfirst, organization={Wolfram Research}, title={HoldFirst}, year={1988}, url={https://reference.wolfram.com/language/ref/HoldFirst.html}, note=[Accessed: 13-June-2026]}