Skip to content

Head

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Head[expr]
    gives the head of expr.
Head[expr, h]
    wraps the result with h, i.e. returns h[Head[expr]].

For atoms, Head returns Integer, Real, BigInt, Rational, Complex,
Symbol, or String; for a compound expression f[...], Head returns f.

Examples

All examples below are verified against the current Mathilda build.

In[1]:= Head[f[x]]
Out[1]= f

In[2]:= Head[3/4]
Out[2]= Rational

In[3]:= Head[a + b, f]
Out[3]= f[Plus]

Implementation notes

builtin_head (in src/part.c) returns the head of its argument via expr_headf for f[...], and the type symbol (Integer, Symbol, List, etc.) for atoms. The 2-arg form Head[expr, h] wraps the result as h[Head[expr]], leaving the outer application for the evaluator to reduce.

  • For functions, returns the symbol or expression acting as the head.
  • For atoms, returns the symbolic type name: Integer, Real, Rational, Complex, Symbol, or String.

Attributes: none registered.

Implementation status

Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

References