Functions: Using Patterns in Delayed Assignment (:=)
Defining Functions with Patterns
Defining functions with patterns probably combines the most useful aspects of Mathematica. Define a function that takes patten matching x as its first argument and an argument matching n as its second argument and returns x to the power:
This works fine, but suppose we had defined x ahead of time
RHS evaluated, it is x^(second argument) which is currently 4^(second argument)
The problem with the above functions is that the evaluation is made immediately. For a function, the argument serves as a placeholder for a future calculation. You do not wish to have the right–hand–side evaluated until the actual values of left–hand–side are specified. The remedy is to use delayed assignment :=
Created by Wolfram Mathematica 6.0 (06 September 2007) | ![]() |