Back: Programming
Previous: Packages
Next: Iterating with Nest and Fold

Programming in Mathematica

Anonymous Functions

Specify a function without naming it (or its parameters)



ArcTan[#] - 0.5 &		(* a function of 1 variable *)
Sqrt[#2 #1] &			(* a function of 2 variables *)
100#1 + 10#2 + #3&		(* a function of 3 variables *)


ArcTan[#] - 0.5 &  [1]

	       Pi
	-0.5 + --
	       4


Sqrt[#2 #1] &     [3,5]

	Sqrt[15]



(7+#^2)&    /@   {a,b,c,1,2,3}			(* Map  *)

	      2       2       2
	{7 + a , 7 + b , 7 + c , 8, 11, 16}



(100#1 + 10#2 + #3)&	@@   {9, 8, 7}	      (* Apply *)

	987