Mathematica: Definitions & Assignments

  

  • x=v — assign a value (Set)
  • {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
     

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
  • ClearAll   
  • Remove
     

Information about Assignments

  • ?x (Information) — get information about all assignments for x
  • DownValues    
  • UpValues  
  • Save

 

Referenced from: Reference.wolfram.com

19587
12/21/2017 2:05:04 PM