Wolfram Language Syntax

The Wolfram Language has a rich syntax carefully designed for consistency and efficient, readable entry of the Wolfram Language's many language, mathematical, and other constructs. In addition to ordinary linear ASCII input, the Wolfram Language also supports full 2D mathematical input.

Basic Syntax

f[x,y] — function arguments go in square brackets

(RefLink[Exp, paclet:ref/Exp]), (RefLink[Do, paclet:ref/Do]), ... — built-in symbols have names beginning with capital letters

Basic Operations

(RefLink[x = val, paclet:ref/Set]) — set a value ((RefLink[=., paclet:ref/Unset]) to clear a value)

(RefLink[x == val, paclet:ref/Equal]) — test equality or represent a symbolic equation ((RefLink[!=, paclet:ref/Unequal]) for unequal)

(RefLink[lhs := rhs, paclet:ref/SetDelayed]) — function etc. definition

(RefLink[a -> b, paclet:ref/Rule]), (RefLink[a -> b, paclet:ref/Rule]) — rule for transformations, options, etc. ((RefLink[:>, paclet:ref/RuleDelayed]) for delayed rule)

(RefLink[expr /. rule, paclet:ref/ReplaceAll]) — replace using a rule ("slash dot")

Mathematics & Operators

a b c — spaces stand for multiplication

nn*^ee — scientific notation

b^^nnnn — number in a base

Patterns

(RefLink[x_, paclet:ref/Blank]) — any expression ("x blank")

(RefLink[x__, paclet:ref/BlankSequence]), (RefLink[x___, paclet:ref/BlankNullSequence]) — sequences of arbitrary expressions ("x double blank", ...)

(RefLink[_, paclet:ref/Blank]), (RefLink[__, paclet:ref/BlankSequence]), (RefLink[___, paclet:ref/BlankNullSequence]) — unnamed patterns

(RefLink[x : p, paclet:ref/Pattern]) — pattern name

(RefLink[p : d, paclet:ref/Pattern]) — pattern default

Pure Functions

(RefLink[expr &, paclet:ref/Function]) — a pure function

(RefLink[#, paclet:ref/Slot]), (RefLink[#2, paclet:ref/Slot]), etc. — arguments in a pure function

(RefLink[#name, paclet:ref/Slot]) — named part of a pure function argument

Short Forms

(RefLink[ f @ expr, paclet:ref/Prefix]) — prefix function application

(RefLink[expr // f , paclet:ref/Postfix]) — postfix function application ("slash slash")

Program Syntax

(RefLink[expr ; expr ; expr, paclet:ref/CompoundExpression]) — sequence of commands ((RefLink[CompoundExpression, paclet:ref/CompoundExpression]))

(RefLink[<< file, paclet:ref/Get]) — input a file ((RefLink[>>, paclet:ref/Put])file, (RefLink[>>>, paclet:ref/PutAppend])file for outputting to a file)

(* … *) — comment

ccc`nnn — symbol in context ccc

Session Syntax

(RefLink[%, paclet:ref/Out]) — most recent output ((RefLink[%, paclet:ref/Out])n for output on line n)

(RefLink[? x, paclet:ref/Information]) — information on symbol x