Basic Objects

Expressions

Expressions are the main type of data in the Wolfram Language.

Expressions can be written in the form h[(Subscript[e, 1]),(Subscript[e, 2]),…]. The object h is known generically as the head of the expression. The (Subscript[e, i]) are termed the elements of the expression. Both the head and the elements may themselves be expressions.

The parts of an expression can be referred to by numerical indices. The head has index 0; element (Subscript[e, i]) has index i. (RefLink[Part, paclet:ref/Part])[expr,i] or expr[[i]] gives the part of expr with index i. Negative indices count from the end.

(RefLink[Part, paclet:ref/Part])[expr,(Subscript[i, 1]),(Subscript[i, 2]),…], expr[[(Subscript[i, 1]),(Subscript[i, 2]),…]], or (RefLink[Extract, paclet:ref/Extract])[expr,{(Subscript[i, 1]),(Subscript[i, 2]),…}] gives the piece of expr found by successively extracting parts of subexpressions with indices (Subscript[i, 1]),(Subscript[i, 2]),…. If you think of expressions as trees, the indices specify which branch to take at each node as you descend from the root.

The pieces of an expression that are specified by giving a sequence of exactly n indices are defined to be at level n in the expression. You can use levels to determine the domain of application of functions like (RefLink[Map, paclet:ref/Map]). Level 0 corresponds to the whole expression.

The depth of an expression is defined to be the maximum number of indices needed to specify any part of the expression, plus one. A negative level number -n refers to all parts of an expression that have depth n.

Symbols

Symbols are the basic named objects in the Wolfram Language.

The name of a symbol must be a sequence of letters, letter-like forms, and digits, not starting with a digit. Uppercase and lowercase letters are always distinguished in the Wolfram Language.

Conventions for symbol names.

Essentially all system-defined symbols have names that contain only ordinary English letters, together with numbers and $. The exceptions are π, ∞, e, i and j.

System-defined symbols conventionally have names that consist of one or more complete English words. The first letter of each word is capitalized, and the words are run together.

Once created, an ordinary symbol in the Wolfram Language continues to exist unless it is explicitly removed using (RefLink[Remove, paclet:ref/Remove]). However, symbols created automatically in scoping constructs such as (RefLink[Module, paclet:ref/Module]) carry the attribute (RefLink[Temporary, paclet:ref/Temporary]), which specifies that they should automatically be removed as soon as they no longer appear in any expression.

When a new symbol is to be created, the Wolfram Language first applies any value that has been assigned to (RefLink[$NewSymbol, paclet:ref/$NewSymbol]) to strings giving the name of the symbol and the context in which the symbol would be created.

If the message (RefLink[General, paclet:ref/General])::newsym is switched on, then the Wolfram Language reports new symbols that are created. This message is switched off by default. Symbols created automatically in scoping constructs are not reported.

Contexts

The full name of any symbol in the Wolfram Language consists of two parts: a context and a short name. The full name is written in the form context`name. The context context` can contain the same characters as the short name. It may also contain any number of context mark characters `, and must end with a context mark.

At any point in a Wolfram Language session, there is a current context (RefLink[$Context, paclet:ref/$Context]) and a context search path (RefLink[$ContextPath, paclet:ref/$ContextPath]) consisting of a list of contexts. Symbols in the current context, or in contexts on the context search path, can be specified by giving only their short names, provided they are not shadowed by another symbol with the same short name.

Contexts used for various specifications of symbols.

With Wolfram Language packages, it is conventional to associate contexts whose names correspond to the names of the packages. Packages typically use (RefLink[BeginPackage, paclet:ref/BeginPackage]) and (RefLink[EndPackage, paclet:ref/EndPackage]) to define objects in the appropriate context, and to add the context to the global (RefLink[$ContextPath, paclet:ref/$ContextPath]). (RefLink[EndPackage, paclet:ref/EndPackage]) prints a warning about any symbols that were created in a package but which are "shadowed" by existing symbols on the context search path.

The context is included in the printed form of a symbol only if it would be needed to specify the symbol at the time of printing.

Atomic Objects

All expressions in the Wolfram Language are ultimately made up from a small number of basic or atomic types of objects.

These objects have heads that are symbols that can be thought of as "tagging" their types. The objects contain "raw data", which can usually be accessed only by functions specific to the particular type of object. You can extract the head of the object using (RefLink[Head, paclet:ref/Head]), but you cannot directly extract any of its other parts.

Atomic objects.

Atomic objects in the Wolfram Language are considered to have depth 0 and yield (RefLink[True, paclet:ref/True]) when tested with (RefLink[AtomQ, paclet:ref/AtomQ]).

Numbers

Basic types of numbers.

All numbers in the Wolfram Language can contain any number of digits. The Wolfram Language does exact computations when possible with integers and rational numbers, and with complex numbers whose real and imaginary parts are integers or rational numbers.

There are two types of approximate real numbers in the Wolfram Language: arbitrary precision and machine precision. In manipulating arbitrary-precision numbers, the Wolfram Language tries to modify the precision so as to ensure that all digits actually given are correct.

With machine-precision numbers, all computations are done to the same fixed precision, so some digits given may not be correct.

Unless otherwise specified, the Wolfram Language treats as machine-precision numbers all approximate real numbers that lie between (RefLink[$MinMachineNumber, paclet:ref/$MinMachineNumber]) and (RefLink[$MaxMachineNumber, paclet:ref/$MaxMachineNumber]) and that are input with less than (RefLink[$MachinePrecision, paclet:ref/$MachinePrecision]) digits.

In (RefLink[InputForm, paclet:ref/InputForm]), the Wolfram Language prints machine-precision numbers with (RefLink[$MachinePrecision, paclet:ref/$MachinePrecision]) digits, except when trailing digits are zero.

In any implementation of the Wolfram Language, the magnitudes of numbers (except 0) must lie between (RefLink[$MinNumber, paclet:ref/$MinNumber]) and (RefLink[$MaxNumber, paclet:ref/$MaxNumber]). Numbers with magnitudes outside this range are represented by (RefLink[Underflow, paclet:ref/Underflow])[] and (RefLink[Overflow, paclet:ref/Overflow])[].

Character Strings

Character strings in the Wolfram Language can contain any sequence of characters. They are input in the form "ccccc".

The individual characters can be printable ASCII (with character codes between 32 and 126), or in general any 8- or 16-bit characters. The Wolfram Language uses the Unicode character encoding for 16-bit characters.

In input form, 16-bit characters are represented when possible in the form ∖[name], and otherwise as ∖:nnnn.

Null bytes can appear at any point within Wolfram Language strings.