Assignments
The Wolfram Language's symbolic architecture supports a highly generalized notion of assignment, in which you can specify a transformation for any class of expressions defined by a Wolfram Language pattern. Simple cases correspond to assignments for "variables", "indexed variables", or "structure elements". Other cases define functions or general transformations.
{x,y}={u,v} — assign multiple values
{x,y}={y,x} — swap values
a[[i]]=v — assign a value to a list/array/expression element
x++ (Increment ) ▪ ++ x (PreIncrement ) ▪ x+= y (AddTo )
x-- (Decrement ) ▪ -- x (PreDecrement ) ▪ x-= y (SubtractFrom )
x*= y (TimesBy ) ▪ x/= y (DivideBy )
AppendTo , PrependTo — add elements to a list
AssociateTo , KeyDropFrom — modify an association
Function Definitions
f[x_]:=body — define a function
Forms of Assignment
lhs=rhs — immediate assignment, with rhs evaluated at the time of assignment
lhs:=rhs — delayed assignment, with rhs reevaluated every time it is used
f/:lhs=rhs , f/:lhs:=rhs — associate assignments with the head f
lhs^=rhs , lhs^:=rhs — define "upvalues" associated with the leading head in lhs
Clearing Assignments
x=. — unset the value of x (Unset )
Clear — clear all values associated with a symbol
Information about Assignments
?x (Information ) — get information about all assignments for x
DownValues ▪ OwnValues ▪ UpValues ▪ SubValues ▪ DefaultValues ▪ ValueQ ▪ Save