KX Community

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

Home Forums kdb+ Why do we put a 0# here: @[`.;t;@[;`sym;`g#]0#]

  • Why do we put a 0# here: @[`.;t;@[;`sym;`g#]0#]

    Posted by mannix on March 17, 2022 at 12:00 am

    I know roughly what apply does:

    In the other apply we are applying to tables in the namespace the inner apply.

    The inner apply is grouping on the sym column and it is a projection hence the empty slot.

    But what exactly is 0# doing here?

     

    mannix replied 6 months, 3 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • Laura

    Administrator
    March 17, 2022 at 12:00 am

    TLDR: the expression initialises a list t of tables in the default namespace, setting the grouped attribute on the symbol column and removing all the table rows.

    How that? The function called is not Apply but Amend At @ in its ternary form.

    The first argument is the default namespace `., which, as a namespace, is also a dictionary.

    The second argument t will be a symbol vector of names of tables in the default namespace; i.e. globals.

    The third argument is the function to be applied to each table. Youve already spotted that the unary projection @[;`sym;`g#] sets the grouped attribute on the sym column. It is composed (by juxtaposition) with the unary projection 0#. Applied to a table, 0# removes all the rows.

    So the function applied to each table named in t is the composition @[;`sym;`g#] 0#. That is, remove the rows and set grouped on the sym column.

Log in to reply.