Friday, May 20, 2016

Riddle 4: What’s Going On Here?

What’s happening in this snippet, and why is it interesting?
% q
KDB+ 3.3 2016.03.14 Copyright (C) 1993-2016 Kx Systems
m32/ 2()core 2048MB adavies air.local 10.37.129.2 NONEXPIRE

q)f:{x+1}
q)\d .foo
q.foo)g:{select f a from x}
q.foo)\d .
q).foo.g([]a:1 2 3)
a
-
2
3
4
q)

Labels: ,

3 Comments:

At May 20, 2016 at 3:27 PM , Blogger Dan Nugent said...

qSQL expressions always execute in the top level namespace.

 
At May 20, 2016 at 7:01 PM , Blogger Aaron Davies said...

Very close, but not quite right.

 
At May 22, 2016 at 4:23 AM , Blogger Akash said...

internally select gets converted into a functional format.And `a is treated as a constant and points to main namespace.

q)\d .foo
q.foo)x:{a+1}
q.foo)y:{value[`a]+1}
q.foo)a:1
q.foo)\d .
q)a:3
q).foo.x[]
2
q).foo.y[]
4
q)value .foo.x
0x0d81410003
,`x
`symbol$()
`foo`a
"{a+1}"
q)value .foo.y
0x0da033410003
,`x
`symbol$()
,`foo
`a
"{value[`a]+1}"

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home