HoldComplete¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
HoldComplete[expr]
shields expr completely from evaluation.
Notes
HoldComplete has attribute HoldAllComplete: it prevents argument evaluation, Sequence flattening, Unevaluated stripping, and Evaluate from firing. Substitution (via ReplaceAll, etc.) still happens inside HoldComplete. HoldComplete is removed by one level of ReleaseHold.Examples (9)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (5)¶
In[1]:= Attributes[HoldComplete]
Out[1]= {HoldAllComplete, Protected}
In[2]:= HoldComplete[1+1, Evaluate[1+2], Sequence[3, 4]]
Out[2]= HoldComplete[1 + 1, Evaluate[1 + 2], Sequence[3, 4]]
In[3]:= HoldComplete[Sequence[a, b]]
Out[3]= HoldComplete[Sequence[a, b]]
In[4]:= HoldComplete[f[1+2]] /. f[x_] :> g[x]
Out[4]= HoldComplete[g[1 + 2]]
In[5]:= ReleaseHold[HoldComplete[Sequence[1, 2]]]
Out[5]= Sequence[1, 2]
Applications (4)¶
Holds its argument, like Hold
But unlike Hold it does not splice Sequence
For contrast, Hold does splice it
ReleaseHold strips the wrapper and evaluates
Implementation notes¶
HoldComplete has no C handler; the attribute table in src/attr.c gives it ATTR_HOLDALLCOMPLETE | ATTR_PROTECTED, so the evaluator suppresses all argument evaluation and the upvalue/Sequence/Unevaluated-stripping machinery as well. ReleaseHold removes the wrapper.
- Attributes:
{HoldAllComplete, Protected}. HoldCompleteprevents argument evaluation,Sequenceflattening inside its own arguments,Unevaluatedwrapper stripping, andEvaluatefrom firing.Evaluatecannot overrideHoldAllComplete.- Structural substitution (via
ReplaceAll,Replace,ReplacePart, etc.) still descends intoHoldCompletebecause substitution is not part of evaluation. HoldCompleteis removed by one layer ofReleaseHold.HoldCompleteis a milder form ofUnevaluatedat top level:HoldCompletealways keeps the wrapper, whileUnevaluatedis typically stripped by the enclosing function.
Attributes: HoldAllComplete, Protected.
References¶
See also: Sequence, Unevaluated, Evaluate, HoldAllComplete, ReplaceAll, Replace, ReleaseHold
- Source:
src/attr.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_releasehold.c - Tests:
tests/test_sequence.c - Tests:
tests/test_unevaluated.c - Tests:
tests/test_upvalues.c
Notes & additional examples¶
Notes¶
HoldComplete[expr] is the strongest hold wrapper: it carries the HoldAllComplete
attribute, so besides holding every argument unevaluated it also suppresses the upvalue
lookup and the Sequence / Unevaluated-stripping that an ordinary Hold still performs.
That is why HoldComplete[Sequence[1, 2], 3] keeps its Sequence intact where Hold
flattens it.
ReleaseHold removes the wrapper and lets the contents evaluate.