Your problem stems from the fact that what is returned by
the sort function is not an array, it is a list. The
function scalar returns the number of elements in an array,
but it does not work on general lists, only on arrays.
Nuance
Baldrick, you wouldn't see a subtle plan if it painted
itself purple and danced naked on top of a harpsichord,
singing "Subtle plans are here again!"
Comment on RE: scalar doesn't work values returned by a function?