kdb+k

Strange view declaration behaviour


In the q 3.6 32bit I see something that I can not explain. Having the same parse trees these two expressions for y1 and for y2 give way too different results:

q)x:3
q)parse"y :: x*10"
::
`y
(*;`x;10)
q)parse"y:: x*10"
::
`y
(*;`x;10)
q)y1 :: x*10
q)y2:: x*10
q)x:5
q)y1
30
q)y2
50

Why the space is so meaningful here?


Solution

  • I believe defining a view in kdb has the condition that there should be no whitespace between the variable and ::

    So in your example, y2 is a view and y1 is not, hence when you redefine x, the value of y2 is updated when referenced and y1 is not