Let's go back now and lift that restriction. Since in many applications the nature of the desired ordering is known before the particular list to be ordered and is constant over many applications to different lists, it makes sense to curry the sorting algorithm so that it takes these arguments separately. The problem is that the actual use of the ordering rule is not in the body of insertion-sort , but inside the insert procedure, which is entirely separate. It is a pleasant surprise to discover that it is legal to do exactly this in Scheme. However, many people find the version that uses a local definition more readable.
Disciplined programmers use embedded definitions only for procedures.
Sorting a vector Finally, let's consider the rather different case in which the values that we want to arrange are presented as a vector and the goal of the sorting algorithm is to overwrite the old arrangement of those values with a new, sorted arrangement of the same values. Initially the boundary is at the left end of the vector. The plan is to shift it, one position at a time, to the right end. When it arrives, the entire vector has been sorted. Here's the plan for the main algorithm, then.