Functional Input Arguments to Functions

Allowing functions to be passed as arguments to a function is a useful feature which allows greater generality and re-use. For example, a sorting function may have a comparison function as a formal parameter. This makes the sorting function more general and reusable, since it can adapt to different comparison schemes. For example, the sort function below sorts an array in decreasing or increasing order depending on the passed compare function.