Short answer: “\001” vs data

Use the vs (vector from scalar) function:

q)fstring
“f1=va\001f2=vb\001f3=vc”
q)”\001″ vs fstring
“f1=va”
“f2=vb”
“f3=vc”
q)

We can combine vs with /: (each right) to break up each component:

q)”=” vs/: “\001” vs fstring
“f1” “va”
“f2” “vb”
“f3” “vc”
q)

Note that you cannot put any space between vs and /:. If you did, that would be a comment.

We might next turn fstring’s contents into a table using a combination of flip and ! (dict):

q)flip "=" vs/: "\001" vs fstring
"f1" "f2" "f3"
"va" "vb" "vc"
q)`field`value ! flip "=" vs/: "\001" vs fstring
field| "f1" "f2" "f3"
value| "va" "vb" "vc"
q)flip `field`value ! flip "=" vs/: "\001" vs fstring
field value
-----------
"f1"  "va"
"f2"  "vb"
"f3"  "vc"
q)

This is almost what we want. Usually, though, you want the field names to be symbols rather than strings. We can do that by applying (@) the $ (cast) operator to (only) the values of the field column:

q)columns: @[flip "=" vs/: "\001" vs fstring; 0; `$]
q)columns
f1   f2   f3
"va" "vb" "vc"
q)flip `field`value ! columns
field value
-----------
f1    "va"
f2    "vb"
f3    "vc"
q)

However, there is a shortcut we can take to deconstruct the string into a table using one of the many variants of 0::

q)flip `field`value ! “S=\001” 0: fstring
field value
———–
f1 “va”
f2 “vb”
f3 “vc”
q)

Not only is this last example more succinct, it’s much faster:

q)\t do[100000;
flip `field`value !
@[flip "=" vs/: "\001" vs fstring; 0; `$]]
485
q)\t do[100000; flip `field`value ! "S=\001" 0: fstring]
110
q)

See also How do I build a ctrl-A delimited string?

The short answer is, q initializes itself, loads data, then code.

The exact sequence is as follows:

  1. load $QHOME/q.k
  2. load $QINIT/q.q or $QHOME/q.q
  3. load tables contained in /directorypath
  4. load scripts /directorypath/*.q (and *.k or .s) in alphabetical order

You can detect if the use of a symbol will increased the total number of interned symbols in the pool using .Q.w:

$ rlwrap q
KDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systems
q).Q.w[]
used| 108432
heap| 67108864
peak| 67108864
wmax| 0
mmap| 0
syms| 537
symw| 15616
q)`1              // force kdb to internalize a new symbol
`1
q).Q.w[]
used| 108432
heap| 67108864
peak| 67108864
wmax| 0
mmap| 0
syms| 538         // increased by 1
symw| 15634       // increase of +18 bytes
q)`12             // force kdb to internalize another
`12
q).Q.w[]
used| 108432
heap| 67108864
peak| 67108864
wmax| 0
mmap| 0
syms| 539         // increase by 1
symw| 15653       // increase of 19 bytes
q)`123
`123
q).Q.w[]
used| 108432
heap| 67108864
peak| 67108864
wmax| 0
mmap| 0
syms| 540         // increase by 1
symw| 15673       // increase of 20 bytes
q)

See this solution to compacting a bloated sym file