Skip to content

Explore sorting

DRAFT

Grade

Iverson saw early that grade is more useful than sort.

 asc x   <==>   x iasc x    / grade up
desc x   <==>   x idesc x   / grade down
Grade makes it possible to sort one list according to the order of another.

Make a table from three lists, sorted by one of them.
q)show(a;b;c):5?'(`3;10;2 cut .Q.a)
bgh  ifn  foh  kdj  eeg
9    2    7    0    1
"st" "ef" "cd" "qr" "qr"

q)([]a;b;c)iasc c
a   b c
----------
foh 7 "cd"
ifn 2 "ef"
kdj 0 "qr"
eeg 1 "qr"
bgh 9 "st"

Sorting in place

FIXME

Collation sequence

All the data types 1–19 are sortable, but you are not confined to their inherent order.

To sort x using a collation sequence C: x iasc C?x

q)show clans: string `Campbell`armstrong`Buccleuch`balmoral
"Campbell"
"armstrong"
"Buccleuch"
"balmoral"

q)asc clans            / lower case sorts after upper
"Buccleuch"
"Campbell"
"armstrong"
"balmoral"

q)show C:"c"$raze 97 65+/:til 26  / collation order
"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"

q)clans iasc C?clans   / sort to collation order
"armstrong"
"balmoral"
"Buccleuch"
"Campbell"

Rank

FIXME