ReleaseHold¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
ReleaseHold[expr]
removes Hold, HoldForm, HoldPattern, and HoldComplete in expr.
Notes
ReleaseHold removes only one layer of Hold etc.; it does not remove inner occurrences in nested Hold etc. functions.Examples (13)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (8)¶
In[1]:= Hold[1+1]
Out[1]= Hold[1 + 1]
In[2]:= ReleaseHold[Hold[1+1]]
Out[2]= 2
In[3]:= ReleaseHold /@ {Hold[1+2], HoldForm[2+3], HoldComplete[3+4]}
Out[3]= {3, 5, 7}
In[4]:= ReleaseHold[f[Hold[1+2]]]
Out[4]= f[3]
In[5]:= ReleaseHold[f[Hold[1+g[Hold[2+3]]]]]
Out[5]= f[1 + g[Hold[2 + 3]]]
In[6]:= ReleaseHold[Hold[Hold[1+1]]]
Out[6]= Hold[1 + 1]
In[7]:= ReleaseHold[Hold[Sin[Pi/6]]]
Out[7]= 1/2
In[8]:= ReleaseHold[{f[Hold[1+2]], g[HoldForm[3+4]]}]
Out[8]= {f[3], g[7]}
Applications (5)¶
Every hold family
Traverses into subexpressions
Only one layer is removed
No wrapper present: acts as identity
Implementation notes¶
builtin_releasehold (src/core.c) calls release_hold_recursive, which walks the tree and strips one layer off every Hold-family wrapper it finds (Hold/HoldForm/HoldPattern/HoldComplete, per is_hold_head), replacing a single-argument wrapper with its content and a multi-argument one with Sequence[...]. It does not recurse into the released contents.
Protected.ReleaseHoldremoves only one layer ofHoldetc.; it does not remove inner occurrences in nestedHoldetc. functions.ReleaseHoldtraverses into subexpressions ofexprand strips any hold wrapper it finds, but does not recurse into the contents of the stripped wrapper.- When
exprdoes not contain any hold wrappers,ReleaseHoldacts as identity. ReleaseHoldremoves all standard unevaluated containers:Hold,HoldForm,HoldComplete, andHoldPattern.
Attributes: Protected.
References¶
See also: Hold, HoldForm, HoldPattern, HoldComplete
- Source:
src/core.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_eval_timestamps.c - Tests:
tests/test_extreme_definite_corpus.c - Tests:
tests/test_mse_trick_corpus.c - Tests:
tests/test_principal_value_corpus.c
Notes & additional examples¶
Notes¶
ReleaseHold[expr] strips the standard unevaluated containers ā Hold,
HoldForm, HoldPattern, and HoldComplete ā and lets the contents evaluate. It
traverses into the subexpressions of expr and removes any wrapper it finds, but
it does not recurse back into the contents it just released, so a nested
Hold[Hold[...]] loses only its outer layer. When expr contains no hold
wrapper, ReleaseHold is the identity.