"logo.gif"  
Main
Read Online
Download PDF
Additional resources
Revision history
Known typos/bugs
Report a bug
License terms
About the author
"node174_1.gif" "node174_2.gif" "node174_3.gif"

4.4.8    Function calls: prefix and postfix syntax

Apart from the standard way to apply a function to some expression, there exist two more short - hand forms  for a function of a single argument: prefix and postfix notation. In the prefix notation, the special symbol < @> is used, while in the postfix notation, the double slash is used : < // > . For example :

"node174_4.gif"

"node174_5.gif"

The prefix form is convenient  to remove extra square brackets  when there is a piece of code with deeply nested function calls, like here :

"node174_6.gif"

"node174_7.gif"

The postfix notation is convenient when we want to apply some operation  which is conceptually less important than the code it encloses, such as Timing measurements or rendering a matrix into a MatrixForm. In this way, it  does not interfere with the main code when we read it:

"node174_8.gif"

"node174_9.gif"

Another reason to use the postfix notation is that the order in which the function calls  are appearing  corresponds to the order in which the transformations are applied to input, and this may make the code more readable in some cases.

One has to be careful with both prefix and postfix forms due to precedence however, as the following examples illustrate:

"node174_10.gif"

"node174_11.gif"

In these cases, the result is such because the precedence of the subtraction or even Power operator is lower than that of the function call in the prefix notation. We have to use parentheses :

"node174_12.gif"

"node174_13.gif"

Another example

"node174_14.gif"

"node174_15.gif"

"node174_16.gif"

"node174_17.gif"

The determinant has not been computed because the < matr > variable stores not just the matrix, but the matrix wrapped in a MatrixForm. This can be verified by looking at the FullForm :

"node174_18.gif"

"node174_19.gif"

Once again, the parentheses must  be used :

"node174_20.gif"

"node174_21.gif"

"node174_22.gif"

Because of these precedence - related complications which often result in bugs, I would not recommend using these forms if this does not bring obvious advantages such as much improved code readability etc. Moreover, they are mostly used in interactive sessions and less so in  complete stand-alone programs.

"node174_23.gif" "node174_24.gif" "node174_25.gif"

Created by Wolfram Mathematica 6.0  (05 February 2009) Valid XHTML 1.1!