Because q is a proprietary language, most of us know it as a language we learned in order to query large datasets. But q is a general-purpose programming language. The 32-bit interpreter is free for non-commercial use. It’s a great tool for general hacking. And lots of datasets need a little hacking.
This is the story of how I used q to hack metadata from 700+ WAV file names for import into Apple Music.
Cleaning up a dataset, finding and fixing problems, is always exploratory, and we get a taste of just how lively and responsive the q REPL is for this work. We use qSQL queries but the work also dips into their functional forms. (We also discover some ways to prevent Apple Music overriding our metadata.)
The script is also an example of functional vector programming in practice.
There is plenty of iteration in the computation but few signs of it in the code. Many of the q primitives, and all qSQL queries, iterate implicitly. Where iteration needs specifying , iteration operators are used, but even these are used sparsely. (It is a common qbie error to use iteration operators when iteration is already implicit.)
There is no use of the do or while control words, and only a single if in the entire script.
Only three functions require multiple lines to define them; the longest has six.
There is also a preference for tacit forms rather than lambdas or setting variables that are read immediately and never used again.