Search code examples
kdb+k

Prefix notation for view definition


I thought that (almost) any q function could be called with prefix and infix notation interchangeably. But then I've tried:

$ q
KDB+ 3.6 2019.04.02 Copyright (C) 1993-2019 Kx Systems
q)a:10
q)b::a
q)a:11
q)b
11
q)view `b
,"a"

looks good, but for:

q)::[b;a]
q)a:12
q)b
11
q)view `b
'type
  [0]  view `b
       ^

something goes wrong. Parse trees look the same:

q)parse "b::a"
::
`b
`a
q)parse "::[b;a]"
::
`b
`a

Could you help me please, why the prefix notation for view definition failes to defive a view?


Solution

  • Views are special. Their definition must start at the very first column:

    q) a::b / not a view but an assignment with b undefined
    'b
      [0]   a::b
               ^
    
    q)a::b / a view
    q)
    

    And they are not parseable with -5!, see the bottom of this page: https://code.kx.com/q/ref/parse/