is an attribute that specifies that all subvalue arguments to a function are to be maintained in an unevaluated form.
SubValuesHoldAll
is an attribute that specifies that all subvalue arguments to a function are to be maintained in an unevaluated form.
Details
- SubValuesHoldAll is typically used to create objects that can be applied to arguments while controlling evaluation.
- In an expression of the form f[a1,a2,…][s11,s12,…][s21,s22,…]…, the ai are normal arguments, and the sij are subvalue arguments. The attribute SubValuesHoldAll indicates that the subvalue arguments are to be held. »
- Even when a function has attribute SubValuesHoldAll, normal arguments are still by default evaluated. The function can additionally have the HoldAll or similar attribute to hold the normal arguments. »
- You can use Evaluate to evaluate the subvalue arguments of a SubValueHoldAll function in a controlled way. »
- Even when a function has attribute SubValuesHoldAll, Sequence objects that appear in its subvalue arguments are still by default flattened, Unevaluated wrappers are stripped, and upvalues associated with the subvalue arguments are used. »
Examples
open all close allBasic Examples (1)
Give the function f the attribute SubValuesHoldAll:
SetAttributes[f, SubValuesHoldAll]As a result, subvalue 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)
Give the function inout the attribute SubValuesHoldAll:
SetAttributes[inout, SubValuesHoldAll]Define a function of two subvalue arguments that returns them wrapped in Hold as well as the first without wrapping:
inout[tag_][in_] := {Hold[in], in, Hold[tag]}The normal argument is evaluated prior to entering the function body, but the subvalue argument is evaluated inside the function:
inout[1 + 1][1 - 1]Give f both the SubValuesHoldAll and HoldAll attributes:
SetAttributes[f, {HoldAll, SubValuesHoldAll}]Neither normal nor subvalue arguments are evaluated:
f[1 + 1, 2 + 2][3 + 3, 4 + 4]Compare with a function that only has the SubValuesHoldAll argument:
SetAttributes[g, {SubValuesHoldAll}]
g[1 + 1, 2 + 2][3 + 3, 4 + 4]As well as one that only has the HoldAll attribute:
SetAttributes[h, {HoldAll}]
h[1 + 1, 2 + 2][3 + 3, 4 + 4]Applications (2)
Use HoldAll and Unevaluated to suppress evaluation of symbols wherever it would occur:
SetAttributes[symbolLength, SubValuesHoldAll];
symbolLength[type_ : "Short"][s_Symbol] := StringLength[If[type === "Full", Context[Unevaluated[s]], ""] <> SymbolName[Unevaluated[s]]]Find the length of a symbol's name even if it has a value:
xyzzy = 1;symbolLength[][xyzzy]symbolLength["Full"][xyzzy]Use the SubValuesHoldAll attribute to build an operator form of EchoTiming:
SetAttributes[echoTiming, SubValuesHoldAll];
echoTiming[label_][expr_] := EchoTiming[expr, label]echoTiming["DSolve Timing"][DSolve[y'[x] + y[x] == a Sin[x], y[x], x]]Properties & Relations (4)
A similar result to SubValuesHoldAll can be achieved by defining a function that returns a Function with the HoldAll attribute:
g[x_] := g[x] = Function[y, Hold[y], HoldAll]
g[1 + 1][2 + 2]However, there is a performance penalty for defining the intermediate pure function:
SetAttributes[f, SubValuesHoldAll];
f[x_][y_] := Hold[y]
f[1 + 1][2 + 2]Table[f[1][2], 1000000];//AbsoluteTiming
Table[g[1][2], 1000000];//AbsoluteTimingUse Evaluate to force evaluation of a subvalue argument of a SubValuesHoldAll function:
SetAttributes[f, SubValuesHoldAll]f[1][1 + 1]f[1][Evaluate[1 + 1]]Use Unevaluated to temporarily treat a function as if it had the attribute SubValuesHoldAll:
f[x_][y_] := Hold[y]f[1][1 + 1]f[1][Unevaluated[1 + 1]]All Sequence objects that appear in subvalue arguments are still by default flattened:
SetAttributes[f, SubValuesHoldAll]
f[][Sequence[a, b, c]]Unevaluated wrappers are stripped prior to entering the function body:
f[][x_] := Hold[x]
f[][Unevaluated[2 + 2]]And upvalues are associated with subvalue arguments still fire:
_[h] ^:= "upvalue"
f[][h]Related Guides
History
Text
Wolfram Research (2026), SubValuesHoldAll, Wolfram Language function, https://reference.wolfram.com/language/ref/SubValuesHoldAll.html.
CMS
Wolfram Language. 2026. "SubValuesHoldAll." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SubValuesHoldAll.html.
APA
Wolfram Language. (2026). SubValuesHoldAll. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SubValuesHoldAll.html
BibTeX
@misc{reference.wolfram_2026_subvaluesholdall, author="Wolfram Research", title="{SubValuesHoldAll}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/SubValuesHoldAll.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_subvaluesholdall, organization={Wolfram Research}, title={SubValuesHoldAll}, year={2026}, url={https://reference.wolfram.com/language/ref/SubValuesHoldAll.html}, note=[Accessed: 12-June-2026]}