How can I generate a list of function calls in the sort order of values of the calls?

My problem is that I have a defined function, say, foo, and I am using the built in Sort function to order a sequence of calls

foo[x1], food[x2], ..., foo[xn]


from lowest value to greatest.

However,

Sort[{foo[x1], foo[x2]}, ..., foo[xn]]


outputs the numerical evaluation of foo[xi]

so that (for example) I get an output like

 {1.1, 3.9 ,..., 9.7}


Assuming foo[x11] evaluates to the lowest, foo[x3] the second lowest and foo[x108] the greatest numerical value, I want the output to be

{foo[x11], foo[x3], ..., foo[x108]}


I also tried

 HoldForm[Sort[{foo[x1], foo[x2]},...,foo[xn]]]


and using HoldForm on the individual elements given to Sort, but neither worked.

Perhaps there is a simpler way of doing what I want to do (list me the order of foo[xi] from lowest value to greatest). Any ideas?

• Maybe you can use SortBy: SortBy[{1.1, 3.9, ..}, foo] Feb 3 '18 at 20:33
• A concrete example is needed here. Otherwise people have to guess what is wanted. Feb 4 '18 at 1:11

foo[x_] = x;

SeedRandom[0]

list = (Inactive[foo] /@ RandomInteger[{100}, 5])


SortBy[list, Activate]


foo = #^2&;
list = RandomReal[{-1, 1}, 5]
Inactive[foo] /@ SortBy[list, foo]


Defer[foo] /@ SortBy[list, foo]


{foo[0.02234],foo[0.027387],foo[0.070565],foo[0.20430],foo[-0.91121]}