This is documentation for Mathematica 5.2, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Mathematica as a Programming Language

Mathematica is an unprecedentedly flexible and intuitive programming language.

Mathematica includes advanced programming methods from modern computer science--as well as adding a host of new ideas of its own.

Mathematica incorporates a range of programming paradigms--so you can write every program in its most natural way.

Procedural programming

List-based programming

Many operations are automatically threaded over lists.

This flattens out sublists.

This partitions into sublists of length 2.

Functional programming

The  is a "pure function". The argument is inserted into the # slot.

Rule-based programming

The _ stands for a single expression; __ stands for any sequence of expressions.

Object-oriented programming

Here are three definitions to be associated with the object h.

This uses the definitions made for h.

String-based programming

Mixed programming paradigms

Many of Mathematica's most powerful functions mix different programming paradigms.

A dozen definitions of the factorial function.

Mathematica gives you the flexibility to write programs in many different styles.

After you have finished with definitions for f, you must clear them.