Search code examples
kdbk

Multiple variable assignment in q


This code looks like multiple variable assignment:

d:`a`b`c!1 2 3
d[`a`b]:10 20

Why is it working this way? And why it is not the same as (a;b):10 20 (which doesn't work)?

I suppose the 2nd line will make only temporary assignment - do not actually replace values. But it will.


Solution

  • It's indexing at top level and assigning new values so it would be the same as:

    q)@[`d;`a`b;:;10 20]
    `d
    

    which also works for global variables in the root context

    q)@[`.;`a`b;:;100 200]
    `.
    q)a
    100
    q)b
    200