cancel
Showing results for 
Search instead for 
Did you mean: 

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

kdb_newbie
New Contributor II

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! 

1 ACCEPTED SOLUTION

gyorokpeter-kx
Contributor
Contributor
.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).

View solution in original post

1 REPLY 1

gyorokpeter-kx
Contributor
Contributor
.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).