The short answer is, q initializes itself, loads data, then code.
The exact sequence is as follows:
- load $QHOME/q.k
- load $QINIT/q.q or $QHOME/q.q
- load tables contained in /directorypath
- load scripts /directorypath/*.q (and *.k or .s) in alphabetical order
Not really. There’s been a meaningful expansion in the language to support tables and such. If you are curious, take a look at the code in $QHOME/q.k, it will help you understand what portions of q are implemented natively vs in k.
Every time you start q, it looks for a file called q.q (in $QHOME, if defined, or current working directory otherwise). If q finds q.q, it will execute it before presenting a prompt or calling any script you provided on the command line.
If you want to call the file something else, or keep it separate from your q installation, you can set the environment variable QINIT to the path to your initialization file.
It is also possible to add k code to q.k (which will be executed before q.q), although we’ve never needed to.