Search code examples
kdb

list append operator that doesn't do automatic unwrapping


Consider

q)-3!1,2
"1 2"
q)-3!1,enlist 2
"1 2"
q)-3!(enlist 1),enlist 2
"1 2"
q)-3!(enlist 1),2
"1 2"

This becomes quite annoying when dealing with lists as data structures representing sets and then sets of sets etc, so I have to define

q)app:{(enlist x) , enlist y}
q)-3!app[1;2]
"1 2"
q)-3!app[1;enlist 2]
"(1;,2)"
q)-3!app[enlist 1;enlist 2]
"(,1;,2)"
q)-3!app[enlist 1;2]
"(,1;2)"

which behaves "as expected" (from statically-typed pov that is). The question is if there exists such operator builtin, and if not, why not?


Solution

  • Answering myself. This operation is enlist of two (or more) arguments :

    q)-3!enlist[1;2]
    "1 2"
    q)-3!enlist[1;enlist 2]
    "(1;,2)"
    q)-3!enlist[enlist 1;enlist 2]
    "(,1;,2)"
    q)-3!enlist[enlist 1;2]
    "(,1;2)"