set a {x u w a i e}
lsort -indices $a - gives: 3 5 4 1 2 0
set b [lsort $a] - gives: a e i u w x (properly sorted list)
lsort -indices $b - gives: 0 1 2 3 4 5 (properly ascending indices)
Pay attention, that before and after sorting the elements have different
indices.
Either there's something wrong - or I don't understand, how it should work
with "-indices" option. My assumption was, that it returns a list of
integers, which will reflect the order of elements AFTER the list will be
sorted. But, as you can see above, in unsorted list x has index 3, and in
the sorted it has (proper) index 5. "a" had index 1 (why?) - after sorting
it has (proper) index 0. In my opinion the indices should be exactly the
same, only their order should be changed. Am I wrong?
So, how does it work, actually?
--
ZB
> So, how does it work, actually?
OK, false assumption: I understand. It does show, how it would like still
using CURRENT indices.
--
ZB
Actually, the indices returned ARE the indices of A in sorted order.
Like most Tcl built-in commands, lsort is non-destructive. It does not
sort the list supplied as its argument in place - rather it returns a
new list (if you do not use -indices) or the list of indices (if you
do) without changing the original list.