Wow! A lot of interest, nice one everyone - I love that recursive solution Evgeniy!
Maybe I missed something but what's the design behavior when the length of the list to be sorted is greater than that of the sort index?
Michael,
The original request that spurred this on was to write a bunch of attribute tags to Excel in a particular order, that order was denoted by a 'reference list'.
But of course, if any tags are surplus to the list, these must be included too.
The attribute tag list would look something like:
((Category_Tag (Type_Tag . Value_Tag)) (Category_Tag (Type_Tag . Value_Tag)) ... )
Where the list would be sorted by referencing the "Category Tag" and the "Type_Tag" and "Value_Tag" are written under each category.
So, that is what spurred this on...