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.
ReleaseHold removes only one layer of Hold etc.; it does not remove inner occurrences in nested Hold etc. functions.
Examples¶
All examples below are verified against the current Mathilda build.
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]}
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.
Implementation status¶
Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
References¶
- Source:
src/core.c - Specification:
docs/spec/builtins/expression-information.md