Entries in iasc (1)

How do I sort?

Short answer: asc and desc:

q)asc 3 5 2 0 1
`s#0 1 2 3 5
q)desc 3 5 2 0 1
5 3 2 1 0
q)

Notice that, in the case of asc, q attaches the `s attribute to the result. (There is no corresponding attribute for a descending sort.)

As an aside, you may be surprised to discover that calling asc on an attribute-free list that happens to be in sorted order will have the `s attribute applied to it as a side effect:

q)list: til 1000
q)attr list
`
q)asc list
`s#0 1 2 3 4 5 6 7 8 9 10 ..
q)list
`s#0 1 2 3 4 5 6 7 8 9 10 ..
q)

Also take a look at iasc and idesc.

Finally, to sort a table instead of a list, see xasc and xdesc. Read more about sorting tables from this faq