The structure of things

Every expression in Mathics is built upon the same principle: it consists of a head and an arbitrary number of children, unless it is an atom, i.e. it can not be subdivided any further. To put it another way: everything is a function call. This can be best seen when displaying expressions in their “full form”:

Nested calculations are nested function calls:

Even lists are function calls of the function List:

The head of an expression can be determined with Head:

The children of an expression can be accessed like list elements:

The head is the 0th element:

The head of an expression can be exchanged using the function Apply:

Apply can be written using the operator @@:

(This exchanges the head List of {1, 2, 3, 4} with Times, and then the expression Times[1, 2, 3, 4] is evaluated, yielding 24.) Apply can also be applied on a certain level of an expression:

Or even on a range of levels:

Apply is similar to Map (/@):

The atoms of Mathics are numbers, symbols, and strings. AtomQ tests whether an expression is an atom:

The full form of rational and complex numbers looks like they were compound expressions:

However, they are still atoms, thus unaffected by applying functions, for instance:

Nevertheless, every atom has a head:

The operator === tests whether two expressions are the same on a structural level:

But

because 3 (an Integer) and 3.0 (a Real) are structurally different.