Wolfram Computation Meets Knowledge

RootSymbol

Contributed by: Ian Ford (Wolfram Research)

Recursively take the head of an expression

ResourceFunction["RootSymbol"][expr]

recursively takes the Head of expr until the Head is Symbol.

Details and Options

If expr is a symbol, ResourceFunction["RootSymbol"][expr] gives expr.
If expr is any other atomic expression, ResourceFunction["RootSymbol"][expr] is equivalent to Head[expr].
For compound expressions of the form f[][],ResourceFunction["RootSymbol"] gives f.

Examples

Basic Examples

The root symbol of a symbol is itself:

In[1]:=
ResourceFunction["RootSymbol"][x]
Out[1]=

The root symbol of an atomic expression is its head:

In[2]:=
ResourceFunction["RootSymbol"]["string"]
Out[2]=

Find the root symbol of a compound expression:

In[3]:=
ResourceFunction["RootSymbol"][f[g[x, y]][h[z]]]
Out[3]=

Resource History