KX Community

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

Home Forums kdb+ May I know how this syntax work please? h".z.pg:{.Q.trp[(0;)@value@;x;{(1;.Q.sbt y)}]}"

  • May I know how this syntax work please? h".z.pg:{.Q.trp[(0;)@value@;x;{(1;.Q.sbt y)}]}"

    Posted by kdb_newbie on June 25, 2023 at 12:00 am

    h“.z.pg:{.Q.trp[(0;)@value@;x;{(1;.Q.sbt y)}]}”

    .z.pg is the message handler on the server

    .Q.trp takes 3 arguments:

    #1 the function: (0;)@value@ (the default value of .z.pg is just {value x}, how does this translate to that?)
    #2 Argument: x (which is the user query)
    #3 The binary function where x is the error string and y is the backtracing object

    And why cannot we simply do this: h”.z.pg:{.Q.trp[{value x};x;{(1;.Q.sbt y)}]}”
    Thank you for all the help!

    kdb_newbie replied 8 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • gyorokpeter-kx

    Member
    June 25, 2023 at 12:00 am
    .Q.trp[(0;)@value@;x;{(1;.Q.sbt y)}]

    means roughly the same as

    .Q.trp[{(0;value x)};x;{(1;.Q.sbt y)}]

    The only difference is that the second form uses a lambda, which appears as an additional level in the stack trace.

    The @ at the end of an expression forces it to be a projection (since it’s a binary operator and we haven’t given it a right argument). But in order to compose this with the (0;) operation (which puts the result in the 2nd element of the list) we need to include another @ otherwise we would be composing the wrong functions.

    .Q.trp[{value x};x;{(1;.Q.sbt y)}] works but it returns a different value in the success case (just the value instead of a list).

Log in to reply.