Skip to content

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)

In[9]:= ReleaseHold[Hold[1 + 1]]
Out[9]= 2

Every hold family

In[10]:= ReleaseHold /@ {Hold[1 + 2], HoldForm[2 + 3], HoldComplete[3 + 4]}
Out[10]= {3, 5, 7}

Traverses into subexpressions

In[11]:= ReleaseHold[f[Hold[1 + 2]]]
Out[11]= f[3]

Only one layer is removed

In[12]:= ReleaseHold[Hold[Hold[1 + 1]]]
Out[12]= Hold[1 + 1]

No wrapper present: acts as identity

In[13]:= ReleaseHold[42]
Out[13]= 42

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.
  • ReleaseHold removes only one layer of Hold etc.; it does not remove inner occurrences in nested Hold etc. functions.
  • ReleaseHold traverses into subexpressions of expr and strips any hold wrapper it finds, but does not recurse into the contents of the stripped wrapper.
  • When expr does not contain any hold wrappers, ReleaseHold acts as identity.
  • ReleaseHold removes all standard unevaluated containers: Hold, HoldForm, HoldComplete, and HoldPattern.

Attributes: Protected.

References

See also: Hold, HoldForm, HoldPattern, HoldComplete

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.