KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ dictionaries as functions

  • dictionaries as functions

    Posted by kdb_newbie on December 6, 2024 at 4:25 pm

    I have 2 functions defined in the test namespace:
    .test.ex.t1:{[data] xxx; xxx;};
    .test.ex.t2:{[data] xxx; xxx;};

    Then, I want call these functions as below:
    .test.ex .’ ((`t1;data);(`t2;data))
    but I run into a length error – what’s the correct syntax?

    unterrainer_ale replied 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • rocuinneagain

    Member
    December 6, 2024 at 4:43 pm

    /: each-right is what you want https://code.kx.com/q/ref/maps/#each-left-and-each-right 

    q).test.ex.t1:{[data] data};

    q).test.ex.t2:{[data] data};

    q).test.ex ./:((`t1;1);(`t2;1))

    1 1

  • unterrainer_ale

    Member
    December 6, 2024 at 4:45 pm

    If you look at your dictionary you can see that your key is a symbol atom, so you have to index by a symbol. Once you have done that, you can pass the value as parameter. This syntax should work

    // Your dictionary

    q).test.ex

    | ::

    t1| {[x] x}

    t2| {[x] x}

    q).test.ex[`t1`t2]@'3 4

    3 4

Log in to reply.